如何让Maven设置(并保持最新)Eclipse项目的构建路径?

时间:2023-01-24 18:26:15

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?

我定义了在pom.xml文件中编译,测试和运行程序的依赖项。但Eclipse仍然有一个单独配置的构建路径,因此每当我更改时,我都必须手动更新另一个。我想这是可以避免的?怎么样?

3 个解决方案

#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.

使用m2eclipse或IAM(以前的Q4E)。两者都提供(以及其他功能)每当执行干净构建时重新计算Maven依赖关系的方法,并将Eclipse的依赖关系呈现为类路径容器。有关详细信息,请参阅Eclipse Maven集成的此比较。

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.

我个人会去m2eclipse,特别是如果你使用AspectJ进行开发。 m2eclipse有一个可选的插件,它将aspectLibraries从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文件。

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.

还有一个eclipse:eclipse的目标,但我发现这比它的价值更麻烦,因为它创建了非常基本的.project和.classpath文件(虽然它对初始项目设置很有用),所以如果你的配置有任何复杂性你每次都要重新申请。公平地说,这是一个较旧的版本,现在可能更好地处理边缘情况。

#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

运行mvn eclipse:eclipse将从你的maven项目中构建eclipse文件,但每次更改pom.xml时都必须运行它。安装eclipse maven插件就像m2eclipse可以让它保持最新

#3


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

我强烈建议您查看M2Eclipse插件。它将保持最新的路径。

#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.

使用m2eclipse或IAM(以前的Q4E)。两者都提供(以及其他功能)每当执行干净构建时重新计算Maven依赖关系的方法,并将Eclipse的依赖关系呈现为类路径容器。有关详细信息,请参阅Eclipse Maven集成的此比较。

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.

我个人会去m2eclipse,特别是如果你使用AspectJ进行开发。 m2eclipse有一个可选的插件,它将aspectLibraries从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文件。

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.

还有一个eclipse:eclipse的目标,但我发现这比它的价值更麻烦,因为它创建了非常基本的.project和.classpath文件(虽然它对初始项目设置很有用),所以如果你的配置有任何复杂性你每次都要重新申请。公平地说,这是一个较旧的版本,现在可能更好地处理边缘情况。

#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

运行mvn eclipse:eclipse将从你的maven项目中构建eclipse文件,但每次更改pom.xml时都必须运行它。安装eclipse maven插件就像m2eclipse可以让它保持最新

#3


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

我强烈建议您查看M2Eclipse插件。它将保持最新的路径。