Java 9 Eclipse does not include Maven dependencies - eclipse

I downloaded the Spring Tool Suite which uses the latest Eclipse (4.7.1a) and imported the code from https://github.com/ConSol/java9-modules-maven-junit-example
This project compiles great from the command line, but in Eclipse, it refuses to take the Maven dependencies into account. On the classpath, I see the maven dependencies specified and everything looks fine, but I still see those errors:
Any help would be appreciated

Related

Eclipse cannot run Spock tests with source folder disappearing

I've encountered a very curious case about Eclipse and Spock tests.
I have Eclipse 4.5.2 (Build id: 20160218-0600) with Groovy compilers plugins installed, Groovy-Eclipse M2E Integration and Groovy-Eclipse Feature, all in version: 2.9.2.xx-201604081629-e45.
In this Eclipse I have a maven project configured to compile and run Spock tests. In Eclipse I have src/test/groovy folder configured as a source folder and it is holding my spock tests. Both maven and Eclipse can run the tests just fine.
Recently my friend has had a problem with the same setup, so I tried to reproduce it. And now I have the same Eclipse 4.5.2 (Build id: 20160218-0600) with Groovy plugin (and this is the weird part, I used the same update site for these plugins but the build version is different, it is: 2.9.2.xx-201607251752-e45). I imported the same maven project, however, when I try to run Spock tests the curious thing happens: the src/test/groovy source folder dissappears from the project and on the console I can see ClassNotFoundException with the name of the Spock test class. Here is a short summary how it looks like:
We tried the same also in Eclipse Neon and Spring STS and we have the same result. (In IntelliJ the same project runs just fine).
I'm starting ti thing that this may be related to the Groovy plugins, which might have got changed in the latest build and a bug was introduced. However, I hope I am mistaken.
Any thoughts?

setting up a maven project in Juno Eclipse

I recently upgraded my Eclipse to Juno and am struggling with the way maven dependencies are handled.
I installed the m2e plugin. Still, many of my projects started complaining about libraries missing as if the dependencies specified in the pom were completely ignored. This happened despite right-clicking on the project, selecting Configure --> Convert to Maven project, which seems to be the replacement for what used to be "Maven --> Enable dependencies" before. When I looked at the Maven dependencies under the project directory, there were many fewer dependencies listed than in my pom.
Running a maven compile on the command line outside of Eclipse allowed my project to build and after selecting Maven --> Update project, I was able to see the dependencies added or removed accordingly to what I specified in the pom.xml.
Bottom line: maven dependencies seem to work now but I had to do some combination of operations I didn't think should have been needed:
- Configure -> Convert to Maven project
- Maven -> Update dependencies
- Run maven outside of Eclipse
To get everything to work when with previous versions of Eclipse, all I had to do was Maven -> enable dependencies. What is the equivalent of this in Juno, i.e. what is the correct way of setting up juno Eclipse to handle properly a maven project?
I have been using Juno for a while now and the reliable way to solve Maven dependencies from within Eclipse after importing a project that is maven based is simply:
Configure --> Convert to Maven project
Maven --> Update project
Running Maven outside of Eclipse doesn't seem to help.
I am not sure why these two steps are now required when they were not before with previous version of Eclipse (at least, two steps were not needed before for sure).
Running
mvn -Declipse.workspace=<path-to-eclipse-workspace> eclipse:add-maven-repo
outside of Eclipse has brought me the problems I described in my comment to the other answer.
On a Mac running Windows under Parallels Desktop on OS X? This similar discussion may solve your problem: intellij - java: Cannot find JDK '1.7' for module

How eclipse maven and ant work together?

I made simple maven project and I opened it with Eclipse. I have installed maven plugin for Eclipse. I'm interested in following:
How Eclipse compiles code when I hit save on my source code (does it use configuration from ant or maven or something else)?
When I run tests from JUnit plugin for Eclipse those Eclipse calls mvn test (I suppose not, but what is then happening exactly)?
Is it possible that maven does the build successfully but Eclipse is
showing errors in code?
The Maven Integration for Eclipse makes it easier to edit POM files, allows you to execute maven builds from within Eclipse and to help with dependency management. It doesn't actually compile your code (unless of course you execute a maven build from within Eclipse). The main help is with the dependency management and writing the .classpath file of your project within Eclipse.
To try and answer your questions:
Eclipse uses its standard mechanism to compile code. With a standard eclipse for java developers your project will have a Java Project nature and Eclipse will then use the Java Development Tools - JDT to compile the code. (Internally this uses an incremental builder to build the code http://help.eclipse.org/juno/index.jsp?topic=%2Forg.eclipse.platform.doc.isv%2Fguide%2FresAdv_builders.htm). What source files it will compile and where it will place the resultant .class files is configured in your project's Java Build Path (which I am guessing the maven plugin may well configure for you)
JUnit support is part of the Java Development Tools as well.
It is possible that maven will successfully build a project outside of Eclipse, but that the same project will show errors within Eclipse. This is usually down to classpath errors (dependencies defined in the project's POM not being added to the classpath in Eclipse). If you are using the maven plugin with eclipse this probably shouldn't happen. If you are not using the maven plugin within eclipse you can execute maven eclipse:eclipse to have maven update the Eclipse .classpath file of the project which should then fix any of these problems.

maven adds dependency but eclipse does not see it

I've created a new project in maven like this:
mvn archetype:generate -DgroupId=com.mycompany.app -DartifactId=my-app -DarchetypeArtifactId=maven-archetype-quickstart -DinteractiveMode=false
After that I use: mvn eclipse:eclipse
The problem is that when I add the project to my IDE, eclipse indicates errors. When I run it I get classNotFound for JUnit. In project properties I see that junit is added to build path
In project properties I see: M2_REPO/junit/junit/3.8.1/junit-3.8.1.jar
But I cant use for example: import junit.framework.Test;
Why is that? To be honest, I have some major problems with dependency in maven and eclipse. Maven adds them correctly but eclipse doesn't see it correctly. It's not only the junit. What should I check/set?
Should I install some plugin to eclipse for maven support ?
EDIT
I thought again about everything. Of course the problem was small. M2_REPO was not recognize by Eclipse. I've added this variable and set it in od maven directory. It worked like a charm.
You can use the m2eclipse plugin for eclipse
http://m2eclipse.sonatype.org/installing-m2eclipse.html
I don't know if having the plugin would solve your problem, I used to do the command line before I started using m2elcipse, I never had the issue that you described
what version of eclipse are you using?

How can I add a classpath entry as a publish/export dependency in an Eclipse dynamic web project?

I successfully created a project using Wicket quickstart and turned it into an Eclipse dynamic web project by running
mvn eclipse:clean eclipse:eclipse -Dwtpversion=2.0
I imported the project to Eclipse without any issues, but got this warning for each JAR:
Classpath entry M2_REPO/**.jar will not be exported or published.
Runtime ClassNotFoundExceptions may result.
I can fix this by using right click → QuickFix on each warning and selecting "Mark the associated raw classpath entry as a publish/export dependency," but this takes a lot of time and would not be possible if there were a lot of dependencies.
There must be a way to have Maven do this for me; what is it?
EDIT: I've found out that using m2eclipse core + Maven Integration for WTP (from m2eclipse extras) resolves my issues.
I'm still interested in how to achieve this without m2eclipse, though, just out of curiosity :p
The two Maven plugins needed to work with web projects in Eclipse are available from the Eclipse Marketplace.
Maven Integration for Eclipse (included in the Java version of Eclipse)
Maven Integration for Eclipse WTP