Tutorial :How can I make Maven set up (and keep up to date) the build path for my Eclipse project?



Question:

I define the dependencies for compiling, testing and running my programs in the pom.xml files. But Eclipse still has a separately configured build path, so whenever I change either, I have to manually update the other. I guess this is avoidable? How?


Solution:1

Use either m2eclipse or IAM (formerly Q4E). Both provide (amongst other features) a means to recalculate the Maven dependencies whenever a clean build is performed and presents the dependencies to Eclipse as a classpath container. See this comparison of Eclipse Maven integrations for details.

I would personally go for m2eclipse at the moment, particularly if you do development with AspectJ. There is an optional plugin for m2eclipse that exposes the aspectLibraries from the aspectj-maven-plugin to Eclipse that avoids a whole class of integration issues.

To enable m2eclipse on an existing project, right-click on it in the Package Explorer view, then select Maven->Enable Dependency Management, this will add the Maven builder to the .project file, and the classpath container to the .classpath file.

There is also an eclipse:eclipse goal, but I found this more trouble than it is worth as it creates very basic .project and .classpath files (though it is useful for initial project setup), so if you have any complications to your configuration you'll have to reapply them each time. To be fair this was an older version and it might be better at handling the edge cases now.


Solution:2

Running mvn eclipse:eclipse will build the eclipse files from your maven project, but you have to run it everytime you change the pom.xml. Installing an eclipse maven plugin can like m2eclipse can keep it up to date


Solution:3

I would strongly encourage you to check out the M2Eclipse Plugin. It will take care of keeping the path up to date.


Note:If u also have question or solution just comment us below or mail us on toontricks1994@gmail.com
Previous
Next Post »