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
.classfiles 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:eclipseto have maven update the Eclipse .classpath file of the project which should then fix any of these problems.