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

给你一囗甜甜゛ 提交于 2019-12-08 08:01:55

问题


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?


回答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.




回答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




回答3:


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



来源:https://stackoverflow.com/questions/1172700/how-can-i-make-maven-set-up-and-keep-up-to-date-the-build-path-for-my-eclipse

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!