当我更改pom.xml文件中的依赖关系时,如何让我的Eclipse-Maven项目自动更新其类路径? [英] How do I get my Eclipse-Maven project to automatically update its classpath when I change a dependency in my pom.xml file?
问题描述
$ p $ m $ m安装
当我从工作区中删除项目并重新导入它时,事情恢复正常。但这是一个繁琐的过程。如何让我的Maven-Eclipse项目自动检测我的pom中的更改并正确更新项目库?
是的,在项目菜单中,构建
将项目导入到Eclipse中时,使用Eclipse自带的内置Maven支持(也称为m2e )。我建议不要使用 mvn eclipse:eclipse
,因为它没有给出最好的结果(正如你所看到的)。 Maven是一个构建和依赖关系管理工具,而不是IDE;期望它管理IDE特定的东西是愚蠢的,在我看来(我意识到Maven团队认为不同,Maven应该负责管理你的IDE,但这是废话)。
所以如果您的系统中有该项目可用,请删除任何特定于Eclipse的文件(通常只是 .classpath
, .project
和文件夹 .settings
),它们由 mvn eclipse:eclipse
生成,你不希望他们干扰这里描述的正确导入过程。然后在Eclipse中,使用File> Import> Maven> Existing Maven Projects导入项目。这应该导致Eclipse和maven之间的更好的集成,包括在pom更改时自动更新Eclipse构建路径。
作为一个快速检查,进行导入后,您应该在项目的构建路径(在属性对话框)的库选项卡中看到一个名为 Maven依赖关系的组。像这样:
如果您希望Eclipse项目配置将在每次更改pom时自动更新,在首选项> Maven 之间有一个(实验性)设置。请注意,尽管如此,可能不太可取,如
I’m using Eclipse Mars with Maven (v 3.3). When I update a dependency in my pom (change the version), my Eclipse-Maven project doesn’t pick it up, even when I right click my project, and select "Maven" -> "Update Project." I know this because I do not see compilation errors in the Eclipse Java editor that I see when I build the project on the command line using
mvn clean install
When I remove the project from the workspace and re-import it, then things get back to normal. However this is a cumbersome process. How do I get my Maven-Eclipse project to automatically detect changes in my pom and update the project libraries appropriately?
And yes, in the "Project" menu, "Build Automatically" is checked.
When you import the project into Eclipse, use Eclipse's own built-in Maven support (aka, m2e). I recommend against using mvn eclipse:eclipse
as it doesn't give the best results (as you're seeing). Maven is a build and dependency management tool, not an IDE; expecting it to manage IDE-specific stuff is silly, in my opinion (I realize the Maven team thinks differently, that Maven should be responsible for managing your IDE, but that's nonsense).
So if you have the project available on your system, delete any Eclipse-specific files (typically just .classpath
, .project
, and folder .settings
), they were generated by mvn eclipse:eclipse
and you don't want them interfering with the "proper" import process described here. Then inside Eclipse, use File > Import > Maven > Existing Maven Projects to import the project. That should result in better integration between Eclipse and maven, including automatically updating the Eclipse build path when the pom is changed.
As a quick check, after doing the import that way, you should see a group called Maven Dependencies in the Libraries tab of the project's Build Path (in Properties dialog). Like this:
If you want the Eclipse project configuration to be automatically updated every time the pom is changed, there's a (experimental) setting for that under Preferences > Maven. Be aware that doing so might not be desirable, though - as mentioned in this feature request, it's a somewhat lengthy process that touches a bunch of stuff in the Eclipse Project; doing that automatically on every pom.xml
change could end up being more trouble than it's worth.
这篇关于当我更改pom.xml文件中的依赖关系时,如何让我的Eclipse-Maven项目自动更新其类路径?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!