75

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?

ROMANIA_engineer
  • 54,432
  • 29
  • 203
  • 199
jvataman
  • 1,357
  • 1
  • 12
  • 13

12 Answers12

103

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

Community
  • 1
  • 1
rustyx
  • 80,671
  • 25
  • 200
  • 267
  • 9
    Thanks. Just a small comment for readers: remember that line break between `-vm` and the actual parameter value is required. – Daniel Fernández Aug 01 '14 at 11:29
  • 1
    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 – Alex Feb 03 '15 at 19:47
  • 1
    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. – David Lotts Aug 10 '15 at 15:18
  • 1
    If you specify `systemPath` [properly](http://maven.apache.org/general.html#tools-jar-dependency), i.e. starting with "../", then you won't have this issue. Maven's `java.home` variable should point to the [JRE](https://web.archive.org/web/20150520200505/https://docs.codehaus.org/display/MAVENUSER/MavenPropertiesGuide), not JDK. The environment variable `JAVA_HOME` on the other hand should point to the JDK. – rustyx Aug 18 '15 at 19:14
  • The 45 people who hit this m2e bug should vote on it in the eclispe bug tracker - https://bugs.eclipse.org/bugs/show_bug.cgi?id=432992 – icyitscold Nov 17 '15 at 15:40
  • 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. – loesak Feb 24 '16 at 07:15
  • Did a "Maven --> Update Project ... " after adding the vm entry and the error disappeared from pom.xml – somnathchakrabarti May 25 '17 at 07:45
  • Five years after the answer in the other SO Q&A (https://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` – leeyuiwah Apr 05 '19 at 16:13
  • This really helped me!. – prashanth-g May 11 '19 at 03:45
96

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>
rustyx
  • 80,671
  • 25
  • 200
  • 267
npe
  • 15,395
  • 1
  • 56
  • 55
  • 7
    Might want to add that your maven command needs to be ran from your jdk(version 6)/lib folder. – Dan W Feb 19 '13 at 22:28
  • 1
    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 – user 923227 May 02 '15 at 19:00
  • This is great..but the mvn install command was giving me build failure.. Adding quotes for the attributes worked for me.. – abhijitcaps Oct 26 '15 at 13:16
  • 2
    @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 ;) – npe Oct 26 '15 at 13:52
  • 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 http://maven.apache.org/guides/mini/guide-3rd-party-jars-local.html – Yogesh Borkhade Sep 18 '17 at 10:19
37

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.

jvataman
  • 1,357
  • 1
  • 12
  • 13
11

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>
Adam LaStrange
  • 115
  • 1
  • 5
6

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>
Krishna
  • 484
  • 7
  • 22
Ravi Macha
  • 687
  • 8
  • 5
1

I use below in my MR project.

<exclusions>
                <exclusion>
                    <artifactId>jdk.tools</artifactId>
                    <groupId>jdk.tools</groupId>
                </exclusion>
</exclusions>
Suman
  • 476
  • 5
  • 7
0

maybe system install jdk package, but maybe some devel tools or plugin.

I find this problem under opensuse env. and I install java-1_6_0-openjdk-devel

the problem is disppeared..

liuyang1
  • 1,575
  • 1
  • 15
  • 23
0

I also faced this problem because I just only installed JRE not with JDK. So , adding dependency for jdk.tools can't fix for me because tools.jar was not exist at my ${JAVA_HOME}/lib/ directory.

Now I downloaded and installed JDK to fix it.

Cataclysm
  • 7,592
  • 21
  • 74
  • 123
0

Change the set of installed JREs in your eclipse. Window > Preferences > Java > Installed JREs, change the location of jre to %JAVA_HOME%/jre, but not something like C:\Program Files\Java\jre7

Sondy Woo
  • 17
  • 1
0

If the jdk.tools is present in the .m2 repository. Still you get the error something like this:

missing artifact: jdk.tools.....c:.../jre/..

In the buildpath->configure build path-->Libraries.Just change JRE system library from JRE to JDK.

0

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"

also check : http://maven.apache.org/guides/mini/guide-3rd-party-jars-local.html

Yogesh Borkhade
  • 616
  • 5
  • 10
-3

Ok, if you are using Windows OS

  1. Go to C:\Program Files\Java\jdk1.8.0_40\lib (jdk Version might be different for you)

  2. Make sure tools.jar is present (otherwise download it)

  3. Copy this path "C:\Program Files\Java\jdk1.8.0_40"

  4. In pom.xml

    <dependency>
    <groupId>jdk.tools</groupId>
    <artifactId>jdk.tools</artifactId>
    <version>1.8.0_40</version>
    <scope>system</scope>
    <systemPath>C:/Program Files/Java/jdk1.8.0_40/lib/tools.jar</systemPath>
    </dependency>
    
  5. Rebuild and run! BINGO!

MichaelS
  • 5,941
  • 6
  • 31
  • 46
Lokesh
  • 661
  • 6
  • 9