Buiding Hadoop with Eclipse / Maven - Missing artifact jdk.tools:jdk.tools:jar:1.6

125,515

Solution 1

jdk.tools:jdk.tools (or com.sun:tools, or whatever you name it) is a JAR file that is distributed with JDK. Usually you add it to maven projects like this:

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

See, the Maven FAQ for adding dependencies to tools.jar

Or, you can manually install tools.jar in the local repository using:

mvn install:install-file -DgroupId=jdk.tools -DartifactId=jdk.tools -Dpackaging=jar -Dversion=1.6 -Dfile=tools.jar -DgeneratePom=true

and then reference it like Cloudera did, using:

<dependency>
    <groupId>jdk.tools</groupId>
    <artifactId>jdk.tools</artifactId>
    <version>1.6</version>
</dependency>

Solution 2

The problem is in the Eclipse Maven support, the related question is here.

Under Eclipse, the java.home variable is set to the JRE that was used to start Eclipse, not the build JRE. The default system JRE from C:\Program Files doesn't include the JDK so tools.jar is not being found.

To fix the issue you need to start Eclipse using the JRE from the JDK by adding something like this to eclipse.ini (before -vmargs!):

-vm
C:/<your_path_to_jdk170>/jre/bin/server/jvm.dll

Then refresh the Maven dependencies (Alt-F5) (Just refreshing the project isn't sufficient).

Solution 3

thanks to npe, adding

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

to pom.xml did the trick.

Solution 4

If you can live without tools.jar and it's only included as a chained dependency, you can exclude it from the offending project:

<dependency>
    <groupId>org.apache.ambari</groupId>
    <artifactId>ambari-metrics-common</artifactId>
    <version>2.1.0.0</version>
    <exclusions>
        <exclusion>
            <artifactId>jdk.tools</artifactId>
            <groupId>jdk.tools</groupId>
        </exclusion>
    </exclusions>
</dependency>

Solution 5

This worked for me:

    <dependency>
        <groupId>jdk.tools</groupId>
        <artifactId>jdk.tools</artifactId>
        <version>1.7.0_05</version>
        <scope>system</scope>
        <systemPath>${JAVA_HOME}/lib/tools.jar</systemPath>
    </dependency>
Share:
125,515
jvataman
Author by

jvataman

Updated on July 05, 2022

Comments

  • jvataman
    jvataman almost 2 years

    I am trying to import cloudera's org.apache.hadoop:hadoop-client:2.0.0-cdh4.0.0 from cdh4 maven repo in a maven project in eclipse 3.81, m2e plugin, with oracle's jdk 1.7.0_05 on win7 using

    <dependency>
        <groupId>org.apache.hadoop</groupId>
        <artifactId>hadoop-client</artifactId>
        <version>2.0.0-cdh4.0.0</version>
    </dependency>
    

    however, I get the following error:

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

    more specific, maven states that the following artifact is missing

    Missing artifact jdk.tools:jdk.tools:jar:1.6
    

    How to solve this?

  • Dan W
    Dan W over 11 years
    Might want to add that your maven command needs to be ran from your jdk(version 6)/lib folder.
  • Daniel Fernández
    Daniel Fernández almost 10 years
    Thanks. Just a small comment for readers: remember that line break between -vm and the actual parameter value is required.
  • Alex
    Alex over 9 years
    Just had this occur where Eclipse was auto detecting the [jdk]\jre\bin\javaw.exe, and when run like this, Maven is unable to locate the tools.jar. Needed to explicitly change Eclipse to run using [jdk]\bin\javaw.exe for Maven to properly find what it calls the com.sun:tools:1.8 jar
  • user 923227
    user 923227 about 9 years
    For the absolute path on windows: the std backslash needs to be replaced by fwd slash - C:/Program Files/Java/jdk1.7.0_67/lib/tools.jar
  • Alex
    Alex almost 9 years
    never add that in your pom if you work with other people :)
  • David Lotts
    David Lotts almost 9 years
    I have to emphasize what @Alex says: use the JDK bin, not the JRE bin for the -vm in the eclipse.ini. @rustyx shows shows the path to the [jdk_path]/ jre /bin and for me, that is what caused my failure of not finding tools.jar -- although I pointed to javaw.exe, not the dll. When I changed it to C:/Program Files/Java/jdk1.8.0_51/bin/javaw.exe and started eclipse, Alt-F5, and the error went away. I was surprised to learn there are two different javaw executables, with different check-sums in the JDK.
  • rustyx
    rustyx almost 9 years
    If you specify systemPath properly, i.e. starting with "../", then you won't have this issue. Maven's java.home variable should point to the JRE, not JDK. The environment variable JAVA_HOME on the other hand should point to the JDK.
  • abhijitcaps
    abhijitcaps over 8 years
    This is great..but the mvn install command was giving me build failure.. Adding quotes for the attributes worked for me..
  • npe
    npe over 8 years
    @abhijitcaps If you're referring to tools.jar by it's full path in Program Files, then this path contains spaces and has to be wrapped with quotes, yes. It's easier to just navigate to that directory and run mvn install:install-file from there ;)
  • icyitscold
    icyitscold over 8 years
    The 45 people who hit this m2e bug should vote on it in the eclispe bug tracker - bugs.eclipse.org/bugs/show_bug.cgi?id=432992
  • loesak
    loesak over 8 years
    it should be mentioned that you dont need to modify the eclipse.ini but have the choice to modify your JAVA_HOME environment variable in the OS to point to the jdk's jre. this fixed the issue for me after restarting eclipse.
  • somnathchakrabarti
    somnathchakrabarti about 7 years
    Did a "Maven --> Update Project ... " after adding the vm entry and the error disappeared from pom.xml
  • Yogesh Borkhade
    Yogesh Borkhade almost 7 years
    try : - - mvn install:install-file -DgroupId=jdk.tools -DartifactId=jdk.tools -Dversion=1.6 -Dpackaging=jar -Dfile="C:\Program Files\Java\jdk\lib\tools.jar" or check maven.apache.org/guides/mini/guide-3rd-party-jars-local.html
  • leeyuiwah
    leeyuiwah about 5 years
    Five years after the answer in the other SO Q&A (stackoverflow.com/a/23129154/1168041) this bug is still there (now is 2019-04-05). I also want to note that be very careful with the path. 1) do not use double quotes around the string. 2) Use forward slash even in windows. 3) Use the jvm.dll 4) make sure you point to jdk.../jre/.... 5) as @Daniel Fernández has pointed out, need a line break after -vm (and not --vm!) For me the winning path is this C:/Program Files/Java/jdk1.8.0_201/jre/bin/server/jvm.dll
  • prashanth-g
    prashanth-g about 5 years
    This really helped me!.
  • MikeKulls
    MikeKulls over 4 years
    This doesn't explain where to put this
  • Alessandro S.
    Alessandro S. about 2 years
    What does precisely mean "you can live without tools.jar"? How can one be sure it's safe to remove it?