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

I'm using Eclipse Mars with Maven (v 3.3). When I update a dependency in my pom (change version), my Eclipse-Maven project does not pick it up even when I right click my project and select "Maven" -> "Update Project". I know this because I don't see any compilation errors in the Java Eclipse editor that I see when I create a project on the command line with

mvn clean install

      

When I remove the project from the workspace and re-import it, everything goes back to normal. However, this is a cumbersome process. How can I get the Maven-Eclipse project to automatically detect changes in my pom and update the project libraries accordingly?

And yes, the "Create Automatically" is checked in the "Project" menu.

+6


source to share


5 answers


When importing a project into Eclipse, use Eclipse's native built-in Maven support (aka, m2e). I recommend using mvn eclipse:eclipse

it as it doesn't give the best results (as you can see). Maven is a build and dependency management tool, not an IDE; expecting it to manage IDE-specific stuff is stupid in my opinion (I understand that the Maven team thinks differently, that Maven should be responsible for managing your IDE, but that is stupid).

So, if you have a project available on your system, delete all Eclipse dependent files (usually only .classpath

, .project

and folder .settings

)) they were generated with mvn eclipse:eclipse

and you don't want them to interfere with the "correct" import process described here. Then inside Eclipse use File> Import> Maven> Existing Maven Projects to import the project. This should result in better integration between Eclipse and maven, including automatically updating the Eclipse build path when the pom changes.

As a quick check after importing, you will see a group called Maven Dependencies in the Libraries tab of the Build Path project (in the Properties dialog box). Like this:



enter image description here

If you want the Eclipse project configuration to automatically update every time the pom changes, there is a (experimental) setting to do this under Preferences > Maven . Keep in mind that this might not be desirable, although as mentioned in this feature request , this is a somewhat lengthy process that affects a bunch of things in an Eclipse project; doing this automatically on every change pom.xml

can be more of a problem than it's worth.

enter image description here

+14


source


Three must-checks you must complete to automatically update your classpath



  • Your repository is not syncing with your Eclipse IDE, please check below settings in your IDE. External Maven
  • Right click any POM.xml from your IDE and check the Maven profile, which should be automatically activated. Also, you cannot enable or disable offline updates.autoactivated
  • Always check your custom settings, which should reflect your local maven.xml settings as shown in the picture below. enter image description here
  • After completing all these checks, update your Eclipse workspace to reflect these changes.
+4


source


Eclipse should update your classpath. If it is not, it means that something is wrong.

It's hard to tell what the problem might be exactly without knowing more about your pom.xml project. More information may be needed to solve the problem, but I'll just do a punch in the dark:

Open the .project file in your project root folder and check the build order and nature there. It is possible that some other nature of the project is also causing the maven2Nature error. Move maven nature and see if it helps anyone.

Alternatively, you might think that Eclipse is not updating your dependencies because it is not adding some of the error indicators to the project that should be there with the new dependencies. Should this case try to clean the current project (project> clean ...). Maven in Eclipse does not necessarily run a full rebuild when dependencies are updated.

If that doesn't work, closing / opening the project can fix the problem faster than re-importing.

0


source


What you wrote should work. Have you checked this:

  • "Clean" mvn install

    from the terminal sees your changes in the POM?

  • maybe, maybe, maybe the plugin is not working, has cached some dependencies in target

    , but mvn clean install

    needed

  • you can start Eclipse in a new workspace and import your project there, sometimes it helps in case of such strange problems.

  • instead of importing a Maven project into Eclipse via m2eclipse

    , you can try to create Eclipse files via the old one mvn eclipse:eclipse

    and see what happens next

  • does it work when you try to import a Maven project into another IDE like the free IntelliJ Community Edition?

0


source


As a last resort, you can uninstall your current Eclipse installation and install the new version. When you add multiple plugins, they can interfere with each other and create strange behavior. After that, don't import the Maven project into the workspace, but create a new one, copy and paste the files you had.

-3


source







All Articles