18

The problem I'm experiencing is that eclipse can't resolve any of the dependencies of my project. This causes problems because even though the dependencies seem to work alright when coding (I get autocompletion) I still get a huge list of errors referring to missing artifacts.

When filtering these, I found the following:

The container 'Maven Dependencies' references non existing library '/home/[...]/.m2/repository/com/sun/tools/1.5.0/tools-1.5.0.jar'

It seems that this dependency was introduced by struts2, who have a profile set up as follows in their pom:

<dependency>
    <groupId>com.sun</groupId>
    <artifactId>tools</artifactId>
    <version>1.5.0</version>
    <scope>system</scope>
    <systemPath>${java.home}/../lib/tools.jar</systemPath>
</dependency>

That systemPath resolves and so I don't see a reason why this would be causing trouble. In any case, is there a way to tell eclipse that this m2eclipse dependency is a system dependency that is not found in the local repository?

wds
  • 31,873
  • 11
  • 59
  • 84

17 Answers17

24

I was facing the same problem and needed to do the following things

  • Added -vm path/to/jdk/bin in eclipse.ini file
  • Clean the existing workspace and reload the project.

It worked for me seamlessly.

Its worth to add that, in my eclipse.ini file I had to add the -vm ... lines at the top of the file. like

-vm
C:\Program Files\Java\jdk1.6.0_27\bin
... ... ...

Make sure that, -vm option is placed before -vmargs as everything after -vmargs is passed directely to vm and selecting a particular is depend on -vm option.

Community
  • 1
  • 1
Samiron
  • 5,169
  • 2
  • 28
  • 55
  • You can also set this up like in the answer by Mojtaba http://stackoverflow.com/a/14100883/896588 or even should. The setting in the eclipse.ini only counts for the runtime of Eclipse itself and gets overriden by anything in the `Installed JREs` dialog for anything you run from inside Eclipse. The safest thing is to do both. – André Stannek Aug 13 '13 at 11:23
  • 1
    I did this back in Indigo, forgot about it and it reoccurred when I upgraded to Kepler. Solved again exactly the same way. – hshib May 07 '14 at 15:03
  • "add the -vm ... lines at the top of the file" is worked for me – Shailesh Pratapwar Sep 07 '15 at 09:31
  • Also, path has to be added till javaw.exe. Ex: -vm C:/Program Files/Java/jdk1.7.0_21/bin/javaw.exe – Shailesh Pratapwar Oct 28 '15 at 07:29
  • For me, it was not needed to clean the existing workspace. Thanks! – abarazal Mar 04 '19 at 04:41
10

I had this issue, but I have fixed by using the steps below:

Case1:

Eclipse by default pointing to JRE but eclipse maven plugin required JDK so point to JDK

Window -> Preperences -> Java -> Installed JREs

change it to JDK

Follow the steps to change to JDK from JRE

  1. In the Eclipse IDE go to: Window… Preferences… Installed JREs
  2. Select defaulted JRE and click on Edit.
  3. Click on Add External Jar
  4. I found tools.jar in “C:\Program Files\Java\jdk1.6.0_22\lib” and added.

Now I can build my project without any issue. Is this the correct way to solve this issue?

Sasikumar Murugesan
  • 4,412
  • 10
  • 51
  • 74
  • 1
    Even though i changed my eclipse to use JDK7, still was getting this error. So did a windows search and found the location of tools.jar in JDK8/lib folder -> added that jar as external jar file in the classpath and it worked! – JavaTec Feb 23 '16 at 21:57
5

I had the same problem - Eclipse couldn't find a tools.jar. As I found out the reason is that Eclipse used a JRE and not a JDK. You have to add a -vm parameter to eclipse.ini that is pointed to your JDK bin directory:
...
-vm
path_to_jdk\bin
...

This should fix the problem.

Eugene
  • 91
  • 2
  • 6
5

excludes tools jar from the struts dependency.

<exclusions>
    <exclusion>
        <groupId>com.sun</groupId>
        <artifactId>tools</artifactId>
    </exclusion>
</exclusions>
Sudheera
  • 355
  • 3
  • 8
  • Works. In my project the dependency to tools was included by Checkstyle 5.7. The problem did not appear until I switched from Java 7 to Java 8. – rwitzel May 02 '14 at 12:12
  • You can have Eclipse do this for you by going to the "Dependency Hierarchy" tab of the pom editor, typing `jdk.tools` into the filter, right clicking the jar (under "Resolved Dependencies") and selecting "Exclude Maven Artifact..." – Tezra May 25 '18 at 19:45
3

Download http://repository.ops4j.org/maven2/tools/tools/1.5.0/ and put the jar in the C:\Documents and Settings\Administrador\.m2\repository\com\sun\tools\1.5.0. Good luck.

glenstorey
  • 5,134
  • 5
  • 39
  • 71
3

You need to verify that Eclipse is using JDK installs.

In Eclipse IDE go to Window / Preferences / Java / Installed JREs point to a JDK installation.

For example: C:\Program Files (x86)\Java\jdk1.6.0_37

andr
  • 15,970
  • 10
  • 45
  • 59
Mojtaba
  • 382
  • 1
  • 2
  • 26
2

I read this and tried various things. What worked for me was this: I changed the windows --> preferences --> java --> installed JREs to point to the JDK instead. That solved this problem.

Ranga Nathan
  • 81
  • 1
  • 4
1

As strange as this may sound, I solved this issue by just re-synchronizing with the SVN repository.

The thing is, I took the entire workspace from another PC, so when I imported the maven project using the m2e plugin, maybe some dependencies didn't synchronize correctly.

I'm posting this just in case someone is desperate with this error and trying all possibilities.

Keith Pinson
  • 7,835
  • 7
  • 61
  • 104
Edu Castrillon
  • 527
  • 1
  • 12
  • 28
1

I also had a similar issue and fixed it the following way. Go to lib directory of JDK installed path in command prompt. Execute the below command to install to install tools.jar.

$mvn install:install-file -DgroupId=sun.jdk -DartifactId=tools \
     -Dpackaging=jar -Dversion=1.6 -Dfile=tools.jar
Kuba hasn't forgotten Monica
  • 95,931
  • 16
  • 151
  • 313
Paramesh Korrakuti
  • 1,997
  • 4
  • 27
  • 39
1
<dependency>
   <groupId>com.sun</groupId>
   <artifactId>tools</artifactId>
   <version>1.6.0</version>
   <scope>system</scope>
   <systemPath>${env.JAVA_HOME}/lib/tools.jar</systemPath>
 </dependency>

Just add this. It will work.

zorze
  • 198
  • 1
  • 6
1

In each project you import into Eclipse, Eclipse makes some files on filesystem - .project, .classpath, a folder .settings,. It seems that Eclipse doesn't update these correctly.

Delete these and import them again.

Clearly, this workaround won't work if this is your 1st import and you already have obtained some issues. Than have a look here Maven2: Missing artifact but jars are in place

Community
  • 1
  • 1
Amio.io
  • 20,677
  • 15
  • 82
  • 117
0

I had the same issue several times and I could fix it following two steps:

  1. I added "-vm C:\\bin" to eclipse.ini or to the link from which I run eclipse.
  2. After having this problem many times, I began to suspect that there may be some m2eclipse cache that is reloaded after some time (one day or so), so I tried a weird solution: temporarily changing the computer time to the following day and restarting Eclipse or closing/cleaning the project and.... IT WORKED!!!

I could repeat the process several times successfully.

A more elegant solution (I haven't had the chance to try it yet), might be to clear m2eclipse caches mentioned at https://stackoverflow.com/a/16444984.

Hope this will help anyone.

Community
  • 1
  • 1
Jorge
  • 184
  • 1
  • 8
0

For Mac users

[1] To find out where your VM is type this /usr/libexec/java_home

[2] vi ./Eclipse.app/Contents/MacOS/eclipse.ini

[3]
-vm
/Library/Java/JavaVirtualMachines/jdk1.7.0_51.jdk/Contents/Home/bin/
-vmargs ........ ........

[4] In Eclipse , Update Maven

[5] Sing All is Well :-)

Sanjay Subramanian
  • 1,509
  • 14
  • 9
0

This issue due to wrong java configuration. every IDE required full JDK pack. becuase tools.jar available inside JDK lib not jre lib

  1. go to control panel change environment path variable to C:\Program Files\Java\jdk1.8.0_31\jre\bin.

  2. change JAVA_HOME to C:\Program Files\Java\jdk1.8.0_31.

  3. open IDE(eclipse or STS) change JRE system library to C:\Program Files\Java\jdk1.8.0_31

then restart IDE. it will work

0

A hacky solution that worked for me:

If m2e is complaining that the following jar is not found in the Maven cache (you can find the bad path in the error log for the pom file, or in the "Java Build Path > Maven Dependencies" list):

${HOME}/.m2/repository/jdk/tools/jdk.tools/1.6/jdk.tools-1.6.pom

then try the following command (fill in JAVA_VERSION_HERE for an installed JDK, e.g. jdk1.8.0_191-amd64, then use the two path sections after .m2/repository/ above to determine the correct groupId, and replace 1.6 with whatever version m2e is complaining about -- it may or may not matter if the JDK you have installed matches the version m2e is complaining about):

mvn install:install-file -Dfile=/usr/java/JAVA_VERSION_HERE/lib/tools.jar \
    -DgroupId=jdk.tools -DartifactId=jdk.tools -Dpackaging=jar -Dversion=1.6

This command copies tools.jar from your JDK and puts it into the Maven cache, also creating a pom.xml file for it so that it can be used by Maven.

Luke Hutchison
  • 8,186
  • 2
  • 45
  • 40
0

This dependency should work as expected. If in doubt, try the command line version of Maven because the Eclipse plugin is very brittle when it comes to dependency resolution.

Unlike other parts of Eclipse, it is unable to create even a partial classpath for the build if something is wrong with the POM, so the error could be something else.

If all else fails, try to install the file into your local repository, so you can see the next error.

Aaron Digulla
  • 321,842
  • 108
  • 597
  • 820
  • I forgot to mention, but as usual everything works fine from the command line. The biggest problem is really that it throws up a couple 100 errors in eclipse, making the problem view a bit hard to use (I am using filtering). I'll attempt to install tools.jar in my local repository and see what comes up. – wds Mar 23 '11 at 11:05
0

I eventually found what was causing it. Seemingly it's a bug in m2eclipse when you are using maven1 repositories. I still had the java.net maven1 repository in my pom; after disabling it everything works again. A very annoying problem to track down because in the end it had nothing to do with finding the tools jar.

wds
  • 31,873
  • 11
  • 59
  • 84