[java] How to add "Maven Managed Dependencies" library in build path eclipse?

I have created a Maven project and I want to add all Maven dependencies in build path of the project in Eclipse. When I go to Java Build Path > Add Library > Maven Managed Dependency > Next in property dialog of the project, it asks me to Use "Maven Project Setting" to configure Maven dependency resolution.

My question is how to add maven dependencies in current build path?

This question is related to java eclipse maven

The answer is


Try:Right Click your project->Maven->Disable Dependency Management. And re-enable dependency management.


If Maven->Update Project doesn't work for you? These are the steps I religiously follow. Remove the project from eclipse (do not delete it from workspace) Close Eclipse go to command line and run these commands.

mvn eclipse:clean
mvn eclipse:eclipse -Dwtpversion=2.0

Open Eclipse import existing Maven project. You will see the maven dependency in our project.

Hope this works.


I could figure out the problem. I was getting following warning on startup of eclipse.

The Maven Integration requires that Eclipse be running in a JDK, because a number of Maven core plugins are using jars from the JDk.

Please make sure the -vm option in eclipse.ini is pointing to a JDK and verify that
Installed JRE's are also using JDK installs

I changed eclipse.ini file and added following and restarted eclipse

-vm
C:/Program Files/java/jdk1.6.0_21/bin/javaw.exe

Now I can see "Maven Dependency" library included automatically in java build path.


If you use an eclipse plugin to do your maven tasks (there are 2 of them : M2ecipse from sonatype the 'official' one and q4e on Google Code) then, there are options in the contextual menus (right click on the project) to do that painlessly.

You can have both plugins running at the same time in your eclipse workbench and use them indifferently on a per project basis.


You can install M2Eclipse and open the project as maven project in Eclipse. It will create the necessary configuration and entries.

This is also useful for subsequent updates to the pom. With maven eclipse plugin, you will need to manually regenerate the eclipse configuration for each changes.


Likely quite simple but best way is to edit manually the file .classpath at the root of your project folder with something like

<classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER">
        <attributes>
            <attribute name="maven.pomderived" value="true"/>
            <attribute name="org.eclipse.jst.component.dependency" value="/WEB-INF/lib"/>
        </attributes>
    </classpathentry>

when you want to have jar in your WEB-IN/lib folder (case for a web app)


I have the same issue using SpringSource Tool Suite. I was importing an existing Maven project which ran fine from the command line. However, when I imported the project using import -> Maven -> existing Maven project, the project did not import correctly import and I could not add the maven managed dependencies library to the build path.

If I ran mvn install from the command line the project built successfully. If I ran mvn eclipse:eclipse and then imported into STS, then everything worked as expected, except of course I'd have to re-run this every time I updated the pom, which was undesirable.

I worked around it by running mvn eclipse:eclipse and then manually updating .classpath to eliminate the M2_REPO dependencies added by eclipse:eclipse and adding the m2eclipse dependency entry:

<classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER">
  <attributes>
    <attribute name="org.eclipse.jst.component.dependency" value="/WEB-INF/lib"/>
  </attributes>
</classpathentry>

Then I imported existing Maven project and it worked as expected.

This is a hack and I'm not sure what other consequences running eclipse:ecplise has when working with m2eclipse. But it did at least allow me to get my project compiling so I could get to coding.


EDIT 1/4/2013

The workaround I posted above will work temporarily, and I never discovered any negative side effects. However, I've had this issue a few times now and each time the problem is that there is some section of the pom that maven accepts but m2eclipse barfs on.

So I recommend removing parts of the pom 1 by 1 until you can mavenize the project successfully. Just keep running maven -> update configuration after each pom edit until it works as it should. I usually start by removing the plugin configuration tag blocks one at a time, starting with the most suspicious (i.e. most complicated).

Once it mavenizes properly, you can revert the pom and it should still work as expected.

After I get running, I'd research the offending configuration(s) to try to figure out what the 'proper' fix is (according to m2eclipse, anyway).

Hopefully this approach leads to the permanent solution instead of settling for a hacky workaround!


Make sure your packaging strategy defined in your pom.xml is not "pom". It should be "jar" or anything else. Once you do that, update your project right clicking on it and go to Maven -> Update Project...


If you imported an existing maven project and Maven dependencies are not showing in the build path in eclipse then right click on project--> Maven--> 'update Project' will resolve the issue.


If you have removed Maven dependency from Library accidentally. Add below in pom.xml

<build>     
        <plugins>
            <plugin>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.3</version>
                <configuration>
                    <source>1.7</source>
                    <target>1.7</target>
                </configuration>
            </plugin>
        </plugins>
</build>

You could also consider to maven-dependency-plugin to your pom:

<plugins>
... 
    <plugin> 
        <artifactId>maven-dependency-plugin</artifactId> 
            <executions> 
                <execution> 
                    <phase>process-resources</phase> 
                    <goals> 
                        <goal>copy-dependencies</goal> 
                    </goals> 
                    <configuration>   
                        <outputDirectory>${project.build.directory}/lib</outputDirectory> 
                    </configuration> 
                </execution> 
            </executions> 
    </plugin> 
...
</plugins>

Than you can run "mvn package" and maven will copy all needed dependencies to your_project_path/target/your_project_name/WEB-INF/lib/ directory. From there you can copy them to your project/lib dir and add as external jars (configuring your project settings buildpath)


If you have m2e installed and the project already is a maven project but the maven dependencies are still missing, the easiest way that worked for me was

  • right click the project,
  • Maven,
  • Update Project...

Eclipse screenshot


Follow these steps

1) Go in projects class path

2) Go in library tab

3) click on Add Library

4) In opened dialogue select Maven Managed Dependencies

5) Click on Next

6) In the new dialogue click on Manage Project Settings

7) In opened dialogue select the check box Resolve dependencies from workspace

8) Click on Restore defaults

9) It will do some process and you will have all your dependencies in your library now.


  • Install M2E plugin.
  • Right click your project and select Configure -> Convert to Maven project.

enter image description here

  • Then a pom.xml file will show up in your project. Double click the pom.xml, select Dependency tab to add the jars your project depends on.

Examples related to java

Under what circumstances can I call findViewById with an Options Menu / Action Bar item? How much should a function trust another function How to implement a simple scenario the OO way Two constructors How do I get some variable from another class in Java? this in equals method How to split a string in two and store it in a field How to do perspective fixing? String index out of range: 4 My eclipse won't open, i download the bundle pack it keeps saying error log

Examples related to eclipse

How do I get the command-line for an Eclipse run configuration? My eclipse won't open, i download the bundle pack it keeps saying error log strange error in my Animation Drawable How to uninstall Eclipse? How to resolve Unable to load authentication plugin 'caching_sha2_password' issue Class has been compiled by a more recent version of the Java Environment Eclipse No tests found using JUnit 5 caused by NoClassDefFoundError for LauncherFactory How to downgrade Java from 9 to 8 on a MACOS. Eclipse is not running with Java 9 "The POM for ... is missing, no dependency information available" even though it exists in Maven Repository The origin server did not find a current representation for the target resource or is not willing to disclose that one exists. on deploying to tomcat

Examples related to maven

Maven dependencies are failing with a 501 error Why am I getting Unknown error in line 1 of pom.xml? Why am I getting "Received fatal alert: protocol_version" or "peer not authenticated" from Maven Central? How to resolve Unable to load authentication plugin 'caching_sha2_password' issue Unable to compile simple Java 10 / Java 11 project with Maven ERROR Source option 1.5 is no longer supported. Use 1.6 or later 'react-scripts' is not recognized as an internal or external command How to create a Java / Maven project that works in Visual Studio Code? "The POM for ... is missing, no dependency information available" even though it exists in Maven Repository Java.lang.NoClassDefFoundError: com/fasterxml/jackson/databind/exc/InvalidDefinitionException