[英]How can I make Maven set up (and keep up to date) the build path for my Eclipse project?
I define the dependencies for compiling, testing and running my programs in the pom.xml files. 我在pom.xml文件中定义了用于编译,测试和运行程序的依赖项。 But Eclipse still has a separately configured build path, so whenever I change either, I have to manually update the other. 但是Eclipse仍然有一个单独配置的构建路径,因此无论何时更改其中一个,都必须手动更新另一个。 I guess this is avoidable? 我猜这是可以避免的吗? How? 怎么样?
Use either m2eclipse or IAM (formerly Q4E ). 使用m2eclipse或IAM (以前称为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. 两者都提供(以及其他功能)一种方法,每当执行一个干净的构建时就重新计算Maven依赖项,并将依赖项作为类路径容器呈现给Eclipse。 See this comparison of Eclipse Maven integrations for details. 有关详细信息,请参见Eclipse Maven集成的此比较 。
I would personally go for m2eclipse at the moment, particularly if you do development with AspectJ. 目前,我个人将使用m2eclipse,尤其是如果您使用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. 有一个用于m2eclipse的可选插件,该插件将AspectLi-Libraries从Aspectj-Maven-plugin公开给Eclipse,从而避免了整个集成问题。
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. 要在现有项目上启用m2eclipse,请在Package Explorer视图中右键单击它,然后选择Maven- > Enable Dependency Management ,这会将Maven构建器添加到.project文件,并将classpath容器添加到.classpath文件。
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. 还有一个eclipse:eclipse目标,但是我发现这麻烦得多,因为它会创建非常基本的.project和.classpath文件(尽管这对于初始项目设置很有用),因此,如果您对配置有任何复杂性您必须每次都重新应用它们。 To be fair this was an older version and it might be better at handling the edge cases now. 公平地说,这是一个较旧的版本,现在处理边缘情况可能会更好。
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. 运行mvn eclipse:eclipse将从您的maven项目中构建eclipse文件,但是您每次更改pom.xml时都必须运行它。 Installing an eclipse maven plugin can like m2eclipse can keep it up to date 安装Eclipse Maven插件就像m2eclipse一样可以使其保持最新状态
I would strongly encourage you to check out the M2Eclipse Plugin . 我强烈建议您检查一下M2Eclipse插件 。 It will take care of keeping the path up to date. 它将确保保持最新状态。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.