Missing tools-1.6.jar with Eclipse and Maven

别说谁变了你拦得住时间么 提交于 2021-02-08 12:22:19

问题


I am trying to get a project to run using Maven in Eclipse, but I am getting this error below. The tools.jar is in the JDK's lib folder, but tools-1.6.jar doesn't seem to exist on my computer. I am using the JDK 1.7 and my JAVA_HOME is pointing to that folder (as is my eclipse.ini) Anyone know where I can get this file or what I might be doing wrong?

The container 'Maven Dependencies' references non existing library C:\Users\sejohnson\.m2\repository\com\sun\tools\1.6\tools-1.6.jar


回答1:


The tools-x.y.z.jar should be provided by your JDK.

Make sure that eclipse is run by JDK and not by JRE by adding -vm option in eclipse.ini.

For example:

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

New line after -vm is crucial.

it should be right above

-vmargs

See also Eclipse Maven Plugin Configuration Problem




回答2:


I had exactly the same problem and end up adding the following dependency to the pom file:

    <dependency>
        <groupId>jdk.tools</groupId>
        <artifactId>jdk.tools</artifactId>
        <version>${java.version}</version>
        <scope>system</scope>
        <systemPath>${JAVA_HOME}/lib/tools.jar</systemPath>
    </dependency>

This fixed the problem and made tools.jar available for QueryDSL plugin in my project. Hope this helps. Note, make sure that JDK version is used instead of JRE.

Edit: Recently noted that problem reappeared when I moved on new dev platform, in my case it was Ubuntu 12.10. The fix was to add ${JAVA_HOME}/bin to the $PATH




回答3:


It could be that your eclipse is defaulting to your 32bit version of your jre. If you do everything right with JAVA_HOME set to C:\Program Files\Java\jdk1.6.0_21\bin and your running a 32bit version of eclipse you'll end up using something like C:\Program Files (x86)\Java\jre6\bin.

once you fix your jdk issue You will need to pass it on the end of a shortcut -vm "C:\Program Files (x86)\Java\jdk1.6.0_31\bin"

Or fix your JAVA_HOME

Other suggestions have been to make sure your eclipse is using the jdk not jre http://gamefromscratch.com/post/2011/11/15/Telling-Eclipse-to-use-the-JDK-instead-of-JRE.aspx

You'll find other post if you search tools.jar or playn another project with this common maven dependency issue.




回答4:


Can you check your pom.xml for dependencies around tools? A good source is mvnrepository.com, finally does your project compile outside of eclipse? Does mvn clean compile work in a dos box or shell? If it does maybe you just need to regenerate the eclipse project files with mvn eclipse:eclipse then refresh your project in eclipse




回答5:


The tools.jar is not provided in any public repository (as I know). If your pom.xml references a file in your local repository you must install it by your own. The pom.xml you are using apparently expects that someone created/installed a tools-1.6.jar in an accecable Maven repository (e.g. to a company central maven repositiory manager like Nexus).

If that does not fit for you try to change the dependency like explained in the Maven FAQs.




回答6:


I had this same problem and it turned out that one of the dependencies in my POM file was transitively adding the dependency to the jdk.tools jar which I didn't need (and was causing the problems with the Eclipse Maven plugin). My solution was to exclude it from the problematic dependency like this:

<dependency>
  <groupId>it.unimi.di</groupId>
  <artifactId>mg4j-big</artifactId>
  <version>${mg4j-big.version}</version>
  <exclusions>
    <exclusion>
      <groupId>jdk.tools</groupId>
      <artifactId>jdk.tools</artifactId>
    </exclusion>
  </exclusions>
</dependency>

Try looking for the dependency that is transitively importing the jdk.tools jar and just exclude like I did above. This should solve your problem.




回答7:


In addition to all the stated above, which could mean different steps to diagnose the problem and ultimately providing a proper solution, I'd first check in a command line (meaning, outside Eclipse runtime). Doing a plain 'mvn clean install' from a command line would give you the following:

  1. Certainty of whether you have the java executables correctly set (as they're the defaults used by all java apps, including of course eclipse,
  2. Certainty that your maven version does resolve the tools*.jar requirement via JDK provisioning adequately

Using these two facts you can rule out problems at Java installation and Maven installation levels. Then you can move on to making Eclipse use the same settings as you can use (JAVA JDK HOME, MAVEN HOME) in a command line, as the other answers above explain with good detail (specifically brimstedt's and josh's).




回答8:


Having the same problem, I had to manually add the tools.jar in eclipse: Preferences -> Java -> Installed JREs -> Select jre -> Edit -> Add External JARs -> Find and select tools.jar -> Finish. Now it works.




回答9:


Here is another option if you are having this build problem. I had the same build problem and i tried all of the above suggestions and the problem was still there. Then i noticed that my system path had the following "C:\ProgramData\Oracle\Java\javapath" as the first item.

I am not sure which program installed it. And when i checked the folder it only had some links ( short cuts). I removed this from the system path and the build error was resolved. Hope this helps someone else in the same situation.




回答10:


Echo @Gopal Ramakrishnan. I had same problem in the env path (windows OS). It has "C:\ProgramData\Oracle\Java\javapath" in which has java.exe, thus impacted the actual jdk path when starting eclipse. Simply remove that resolved the problem. I am pretty sure the "C:\ProgramData\Oracle\Java\javapath" was quietly added by oracle "sql developer"...




回答11:


In my case it turned out that I had this dependency in the pom.xml

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

However JAVA_HOME was set on startup of Eclipse to a JRE instead of a JDK.

So the tools.jar in fact did not exist for this reason



来源:https://stackoverflow.com/questions/7217291/missing-tools-1-6-jar-with-eclipse-and-maven

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!