简体   繁体   English

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

[英]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 ). 使用m2eclipseIAM (以前称为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.

相关问题 如何在Eclipse中备份我的java项目? - How can I back-up my java project in Eclipse? 如何使用Eclipse,Maven,Grails和git设置新的Java项目? - How do I set up a new Java project with Eclipse, Maven, Grails and git? 如何在安装了 java 8 的机器中为 java 6 项目设置构建路径? - How to set up build path for java 6 project in java 8 installed machine? 在Eclipse中,在依赖于maven项目的动态Web项目中,如何从maven项目中拾取jar? - In Eclipse, in a dynamic web project that is dependent on a maven project, how do I pick up jars from the maven project? 如何设置我的 java maven 项目以便导出 - how to set up my java maven project so it will export 如何让eclipse在我的m2e maven项目中检测到新的Java类? - How can I make eclipse detect my new java class in my m2e maven project? 如何使用Maven设置构建脚本? - How do I set up a build-script with Maven? 在 github 上设置 maven 工作流时,我不断收到此错误:“构建无法读取 1 个项目 -> [帮助 1]” - When setting up a maven workflow on github I keep getting this error: “The build could not read 1 project -> [Help 1]” Maven eclipse:pom.xml的项目配置不是最新的 - Maven eclipse: project configuration is not up to date with pom.xml 我如何使用 Maven 加快构建过程 - How I can speed up the build process using Maven
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM