开发者

Missing tools.jar in local repository breaks m2eclipse

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 autocomple开发者_StackOverflow社区tion) 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?


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.


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?


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.


excludes tools jar from the struts dependency.

<exclusions>
    <exclusion>
        <groupId>com.sun</groupId>
        <artifactId>tools</artifactId>
    </exclusion>
</exclusions>


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.


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


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.


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.


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


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


<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.


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.


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.


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 :-)


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.


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


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜