How do I get my Eclipse-Maven project to automatically update its classpath when I change a dependency in my pom.xml file?

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:

enter image description here

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.

enter image description here

Leave a Comment