Missing Maven dependencies in Eclipse project

437,242

Solution 1

Problem solved!

I don't know what exactly solved it, but I did 4 things in Eclipse:

  • Window->Preferences: Maven->Installations: Global settings -> open file and hardcoded localRepository
  • Project->Clean
  • right click on project: Maven->Update dependencies
  • right click on project: Maven->Update project configuration

I guess it was the Update dependencies since right after first two there were no change.

Solution 2

Well, I tried everything posted here, unfortunately nothings works in my case. So, trying different combinations I came out with this one that solved my problem.

1) Open the .classpath file at the root of your eclipse's project.

2) Insert the following entry to the file:

<classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER">
        <attributes>
            <attribute name="maven.pomderived" value="true"/>
            <attribute name="org.eclipse.jst.component.nondependency" value=""/>
        </attributes>
</classpathentry> 

Then, rebuild your project at eclipse (Project->Clean-Build). You now can check at the Java Build Path of you project at the Libraries tab the Maven Dependencies included: enter image description here

Solution 3

I'm also new to Eclipse, and I've been having a similar problem where Eclipse just won't recognize an import statement, even though all signs point to the dependency having been successfully downloaded.

You should check that your dependency file has actually been downloaded by going to the command line and typing

mvn dependency:tree

If you see your package there, then but Eclipse doesn't acknowledge it, the thing that works for me (sometimes) is to go to the terminal, cd into the project folder, and type

mvn eclipse:clean then mvn eclipse:eclipse

Finally refresh project in eclipse

I don't know why this works, and sometimes it doesn't work once, then doing it again does work... so worth a try!

Solution 4

I had this issue for dependencies that were created in other projects. Downloaded thirdparty dependencies showed up fine in the build path, but not a library that I had created.

SOLUTION: In the project that is not building correctly,

  • Right-click on the project and choose Properties, and then Maven.

  • Uncheck the box labeled "Resolve dependencies from Workspace projects"

  • Hit Apply, and then OK.

  • Right-click again on your project and do a Maven->Update Snapshots (or Update Dependencies)

And your errors should go away when your project rebuilds (automatically if you have auto-build enabled).

Solution 5

My Project was just screwed up. Here is how I fixed it for Eclipse Indigo x64 (J2EE 3.7.3):

  1. Deleted my POM file (backedup of course).
  2. Project Context Menu > Maven > Disable Maven Nature.
  3. Deleted the project (but not contents on disk).
  4. Re-imported as Import > General > Existing Project.
  5. Project Context Menu > Configure > Convert to Maven Project....
  6. Accept defaults from Maven wizard.
  7. Overwrite POM with your backedup POM. (Now you have Maven Dependencies folder).
  8. Maven Update/Clean for good measure.

Hope that helps someone. :)

Share:
437,242
hostnik
Author by

hostnik

Updated on July 22, 2022

Comments

  • hostnik
    hostnik almost 2 years

    We have a project set up with maven for resolving dependancies. It usually works fine, but now I am trying to compile and run it on a new PC and I have problem with missing dependencies in Eclipse.

    What is funny is that if I run "mvn package" in console or in eclipse, it works fine and even produces war containing all necessary jars. Only Eclipse complains with "The project was not built since its build path is incomplete. Cannot find the class file for org.slf4j.Logger...". If I compare the project with some other computer (where project works fine), I notice that there are quite a few libraries missing under "Maven dependencies" listing in Eclipse. Eventhough they are in the packaged war and they can be found also under repository folder.

    So, the jar-s are there just Eclipse won't list them all under "Maven dependencies". What can I do?

    Computer is running on Windows 7 with 64bit java & eclipse.

  • Sean Patrick Floyd
    Sean Patrick Floyd over 13 years
    Project -> clean usually does the job in cases like this, but sometimes you also have to do mvn test-compile (or something similar) on the shell
  • hostnik
    hostnik over 13 years
    I know "Project->Clean" and I've tried it, but it didn't help at first.
  • Ranger
    Ranger almost 13 years
    It was the last point. Update project configuration will add a "Maven Dependencies" library to your project.
  • ngreen
    ngreen almost 12 years
    This helps me! I don't know what's wrong, but I'm using 64-bit Juno / Springsource 3 and it always fails to import my Maven projects correctly. If I check out as a regular project, rename my POM, then follow your directions from step 5 onward, it works. Otherwise, nothing I try will get the Maven dependencies added to my project aside from command-line mvn eclipse:eclipse which is just awful.
  • duma
    duma almost 10 years
    FYI, I first had to right click on my project, go to Configure and "Convert to Maven project."
  • Anatch
    Anatch over 9 years
    I did this but I still have not the maven dependencies folder. Here is my pom.xml file and I think it is why I have this problem: <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <groupId>antlr.tuto.calco</groupId> <artifactId>CalculatriceAntlr</artifactId> <version>0.0.1-SNAPSHOT</version> </project>
  • Scott McIntyre
    Scott McIntyre over 9 years
    Thanks, that resolved my issue. Seems to point to it being an Eclipse bug.
  • evaldeslacasa
    evaldeslacasa almost 9 years
    Expanding on Eduard Wirch's answer, I also had to check the "Force Update of Snapshots/Releases" box found at Maven->Update Project... window. My missing artifact was a Snapshot and somehow wasn't updating well without forcing it.
  • Amit Kumar
    Amit Kumar almost 9 years
    This is the first thing everyone should try. Open the .classpath file that will be in your project directory with notepad and add the lines mentioned and refresh your project.
  • yeaaaahhhh..hamf hamf
    yeaaaahhhh..hamf hamf over 8 years
    This worked where everything else failed. But do i have to do this for every project i create? Why doesnt it work automatically? What is the real problem?
  • Mat Gessel
    Mat Gessel about 8 years
    Sigh, this is still broken in m2e 1.6.2.20150902-002. Tested with a fresh vanilla Eclipse install on Mac OS X / JDK 1.8. Eclipse IDE for Java Developers Version: Mars.2 Release (4.5.2) Build id: 20160218-0600 I wonder if this plugin requires Eclipse Java EE to work properly?
  • DarioBB
    DarioBB about 8 years
    Hey, there is no such thing as Maven->Update Snapshots (or Update Dependencies). If I go right click, there is no Maven option? Where is located what you described? I'm looking but can't find description after you hit Apply
  • IceBox13
    IceBox13 about 8 years
    @DarioBB This answer is nearly 5 years old. I haven't worked in Eclipse for well over a year. I have no idea if this option is still available or not. I may not be in the most recent version.
  • Manuel Manhart
    Manuel Manhart about 8 years
    this answer should be the first one. The only one which worked ;-) thx
  • Sagar007
    Sagar007 over 7 years
    I really dont know where is the problem but I have follow above steps and its working really fine. It causes error like class not found, xml dtd not found. But now it is resolved. Thanks Buddy. Upvote.
  • versvs
    versvs almost 7 years
    Magic! still valid for Eclipse 4.4.2
  • cjones26
    cjones26 almost 7 years
    This pointed me in the correct direction by showing me that there were issues with my settings.xml file! Thank you, @rogueleaderr!
  • Zack Zilic
    Zack Zilic over 6 years
    yeah, it worked for my friend, solved all her problems and headaches. Unfortunately didn't work for me.
  • Jack Straw
    Jack Straw over 6 years
    I had to change the User Settings 'settings.xml' to be the one under my '.m2' directory. It was previously set to one under the Maven install dir.
  • nir
    nir over 6 years
    This messes up workspace in newer version of eclipse. Next time when I open eclipse it gives error in '.metadata' dir and eclipse fails to open.
  • Ivana
    Ivana about 6 years
    This solution worked for me in Eclipse neon. Do Maven > Update Project (not Update Snapshots) afterwards.
  • Tarun Gupta
    Tarun Gupta almost 6 years
    Thanks! this solution worked best for me, just one correction tough, I had to close and reopen the project.
  • Tahir Mehmood
    Tahir Mehmood over 5 years
    Wonderful. This worked for me as well. In my project, I couldn't see maven dependencies. Now visible and added to build-path as well. Thanks!
  • user3289695
    user3289695 over 5 years
    It works, but, why doesn't eclipse do this by itself any longer?
  • Indrajeet Gour
    Indrajeet Gour almost 5 years
    It worked for me too but could someone explain what has happen behind the scene??
  • Vanaja Jayaraman
    Vanaja Jayaraman over 4 years
    It worked for me but still the jars are missing. showing with red color cross
  • Bill Naylor
    Bill Naylor over 4 years
    I am running under cygwin, I noticed that only this project was not building under eclipse, though I got successful build (with mvn) on the command line. After running mvn eclipse:eclipse all the dependencies were added to the classpath in the eclipse project and the project looked fine. ++
  • NuCradle
    NuCradle about 4 years
    This did it for me. Thanks.
  • chance
    chance about 4 years
    This works for me. What I have inserted to .classpath file is:<br/> <classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER"> <attributes> <attribute name="maven.pomderived" value="true"/> </attributes> </classpathentry>
  • Ramaraj Karuppusamy
    Ramaraj Karuppusamy almost 4 years
    Working for me. Perfect fix.
  • Cromax
    Cromax over 3 years
    Keep in mind that "Project files created with the maven-eclipse-plugin are not supported in M2Eclipse".
  • strash
    strash over 3 years
    finally this worked for me.. all the other answers just wasted my time
  • Abdollah
    Abdollah almost 3 years
    Worked well for me!
  • camria
    camria almost 3 years
    What a pain! Every time I import this project to a new VM I have issues with Eclipse/Maven and I don't think the same solution has worked 3 times. Luckily for me, this one has worked this time. Thanks! I'll add it to my list of possible solutions, which is ever growing :-/
  • camria
    camria almost 3 years
    Worth noting: this has removed the Maven nature of my project. So, after the above is done, also right-click on the project -> Configure -> Convert to Maven Project; then, right-click again on the project -> Maven -> Update Project...