Missing artifact com.sun:tools:jar

JavaMavenPlayn

Java Problem Overview


I've been following the getting started tutorial, but am stuck after I imported the playn project using Maven. I am using Eclipse Indigo running on 64bit Windows 7.

All the imported projects have the same error:

Missing Artifact com.sun:tools:jar in all the pom.xml files.

After a couple hours of searching forums I have tried:

Installing the latest Java 1.6.029 Changing my JAVA_HOME environment variable to point to \program files\Java\jdk1.6_029 Changing my Eclipse Java preferences to use the JRE jdk1.6_029.

I would really like to experiment with playn, but why there are a few posts I can't seem to find a consenus answer on the solution. Some people say Sun removed something from the 64bit jdk, others say you must edit your xml files, many people have said you have change your JAVA_HOME, and another said you have to change your VM options for Eclipse.

Any help on clearing this up would be appreciated, and possibly useful for many, since I do not have a particularly odd setup here.

(edit) Here is the pom.xml in the first project. Eclipse flags error in the line which says:

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
  <modelVersion>4.0.0</modelVersion>

  <parent>
    <groupId>com.googlecode.playn</groupId>
    <artifactId>playn-project</artifactId>
    <version>1.1-SNAPSHOT</version>
  </parent>

  <artifactId>playn-android</artifactId>
  <name>PlayN Android</name>
  <packaging>jar</packaging>

  <repositories>
  </repositories>

  <dependencies>
    <dependency>
      <groupId>com.googlecode.playn</groupId>
      <artifactId>playn-core</artifactId>
      <version>${project.version}</version>
    </dependency>

    <!-- needed because Android uses the same JSON code as playn-java;
         that should be factored into a library shared by both backends -->
    <dependency>
      <groupId>com.googlecode.playn</groupId>
      <artifactId>playn-java</artifactId>
      <version>${project.version}</version>
    </dependency>

    <dependency>
      <groupId>com.google.android</groupId>
      <artifactId>android</artifactId>
      <version>${android.version}</version>
      <scope>provided</scope>
    </dependency>

    <dependency>
      <groupId>junit</groupId>
      <artifactId>junit</artifactId>
      <version>4.8.1</version>
      <scope>test</scope>
    </dependency>
  </dependencies>

  <build>
    <sourceDirectory>src</sourceDirectory>
  </build>
</project>

Java Solutions


Solution 1 - Java

I just posted over on this question about this same issue and how I resolved it, but I'll paste (and expand on) it here as well, since it seems more relevant.

I had the same issue when using Eclipse in Windows 7, even when I removed the JRE from the list of JREs in the Eclipse settings and just had the JDK there.

What I ended up having to do (as you mentioned in your question) was modify the command-line for the shortcut I use to launch Eclipse to add the -vm argument to it like so:

-vm "T:\Program Files\Java\jdk1.6.0_26\bin"

Of course, you would adjust that to point to the bin directory of your JDK install. What this does is cause Eclipse itself to be running using the JDK instead of JRE, and then it's able to find the tools.jar properly.

I believe this has to do with how Eclipse finds its default JRE when none is specified. I'm guessing it tends to prefer JRE over JDK (why, I don't know) and goes for the first compatible JRE it finds. And if it's going off of Windows registry keys like Vladiat0r's answer suggests, it looks for the HKLM\Software\JavaSoft\Java Runtime Environment key first instead of the HKLM\Software\JavaSoft\Java Development Kit key.

Solution 2 - Java

I had the same trouble while developing a simple, web service application, in my case I had to add a codehous plug in in order to get jaxws libraries. However, maven pom kept on asking about the tools jar file.

I have to say above comments are correct, you can include the below entry in the pom file:

<dependency>
   <groupId>com.sun</groupId>
   <artifactId>tools</artifactId>
   <version>1.6</version>
   <scope>system</scope>
   <systemPath>C:\Program Files\Java\jdk1.6.0_29\lib\tools.jar</systemPath>
 </dependency>

But, what will it happen when you have to deploy to a production instance? You could replace the path with a reference to a system environment variable but that still does not look good, at least to me.

I found another solution in a StackOverflow comment:

https://stackoverflow.com/questions/5756299/maven-3-artifact-problem

<dependency>
    <groupId>org.apache.struts</groupId>
    <artifactId>struts2-core</artifactId>
    <version>${struts2.version}</version>
    <exclusions>
        <exclusion>
            <artifactId>tools</artifactId>
            <groupId>com.sun</groupId>
        </exclusion>
    </exclusions>
</dependency>

They suggest including an exclusion statement for tool jar and it works. So summarizing: you can include an exclusion rule within your dependency and avoid having the tool.jar issue:

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

Solution 3 - Java

I ran into the same problem and the way I was able to resolve it was add the dependency location of tools.jar into the pom.xml. Like so:

 <dependency>
   <groupId>com.sun</groupId>
   <artifactId>tools</artifactId>
   <version>1.6</version>
   <scope>system</scope>
   <systemPath>C:\Program Files\Java\jdk1.6.0_29\lib\tools.jar</systemPath>
 </dependency>

Make sure you change the <systemPath> to where ever your tools.jar file is located.

Solution 4 - Java

None of the other answers did it for me. What did it was to check for "Dependency hierarchy" of the pom.xml in eclipse, where giving a filter 'tools' revealed that I had a real dependency to tools.jar:

Eclipse View

So the culprit for me was this:

<dependency>
    <groupId>com.github.markusbernhardt</groupId>
    <artifactId>robotframework-selenium2library-java</artifactId>
    <version>1.4.0.7</version>
    <scope>test</scope>
</dependency>

Adding an exclusion fixed it:

<dependency>
    <groupId>com.github.markusbernhardt</groupId>
    <artifactId>robotframework-selenium2library-java</artifactId>
    <version>1.4.0.7</version>
    <scope>test</scope>
    <exclusions>
        <exclusion>
            <artifactId>tools</artifactId>
	        <groupId>com.sun</groupId>
	    </exclusion>
	</exclusions>  
</dependency>

The exclusion doesn't seem to have any downsides to it.

Solution 5 - Java

The same with me and Windows 7. I ended up adding two lines to eclipse.ini:

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

I tried using %JAVA_HOME% there, but it did not work.

Solution 6 - Java

I solved this problem in Eclipse 4.3 settings - only by adding JDK libraries to JRE's libraries.

Go windows -> settings -> Java -> installed JREs -> select JDK and click Edit -> click Add External JARs and add tools.jar (placed in JDK/lib)

Solution 7 - Java

Check the JDK version on your machine and in pom.xml both should be same

<dependency>
	<groupId>sun.jdk</groupId>
	<artifactId>tools</artifactId>
	<version>1.8</version>
	<scope>system</scope>
	<systemPath>C:\Program Files\Java\jdk1.8.0_192\lib\tools.jar</systemPath>
</dependency>

Solution 8 - Java

If this problem still happens, it might be because of a JDK of version equal or greater than 11.

The tools.jar archive has been removed from the lib folder in those JDK's (see this answer to a similar question). In that case, try to use other versions of the libraries, that do not rely on the com.sun:tools library.

Solution 9 - Java

If you are seeing this on newly installed/upgraded Operating system, it is just because JAVA_HOME is not set properly.

we need to set JAVA_HOME properly. For example on mac: if I want to use java version 1.8.0_261

export JAVA_HOME=`/usr/libexec/java_home -v 1.8.0_261`

Solution 10 - Java

I also ran into the same problem

can be due to any of these -->

  1. You have installed JRE instead of JDK. (Go ahead and install JDK )
  2. JDK Path is not configured properly or your IDE is using a completely wrong SDK (See project Structure in case of Intellij)
  3. You are using wrong JDK Version , tools.jar was removed from jdk since version 9 (https://docs.oracle.com/en/java/javase/13/migrate/migration-guide.pdf) for this you can resolve by using proper JDK(< 9) Screenshot from Oracle migration doc

Solution 11 - Java

After struggling for a while I finally got this to work with eclipse.ini instead of the command line. After finally reading the documentation I realized that the -vm argument must be on a separate line, unquoted, and ahead of any -vmargs:

-vm
C:\Program Files\Java\jdk1.7.0_45\bin\javaw.exe

Solution 12 - Java

I got similar error. This is because JDK is not properly set in eclipse. Cucumber needs JDK along with JRE, so add below dependency in your pom.xml

<dependency>
  <groupId>com.sun</groupId>
  <artifactId>tools</artifactId>
  <version>1.6</version>
  <scope>system</scope>
  <systemPath>C:\Program Files\Java\jdk1.8.0_101\lib\tools.jar</systemPath>
</dependency>

Solution 13 - Java

In the effective POM tab of the pom files, I see the following derive path: C:\Program Files\Java\jre6/../lib/tools.jar and I think it's not a valid path in Windows. I tried copying the tools.jar in the jre6/lib folder as well as in Java/lib without success.

The value "C:\Program Files\Java\jre6" comes from the registry

HKEY_LOCAL_MACHINE\SOFTWARE\JavaSoft\Java Runtime Environment\1.6.0_30
HKEY_LOCAL_MACHINE\SOFTWARE\JavaSoft\Java Runtime Environment\1.6

And set the JavaHome key to where your jdk JRE is installed. Then all the compiler errors went away.

Reinstalling the JDK didn't fix it. Setting the JAVA_HOME or java.home system environment variable didn't help.

The other alternative I've seen is adding the dependency with the right path in each pom xml file, but the playn-samples has lots of files that is a ridiculous pain to have to edit.

This is the effective POM results, which show the WRONG path!

 <dependency>
      <groupId>com.sun</groupId>
      <artifactId>tools</artifactId>
      <version>1.6</version>
      <scope>system</scope>
      <systemPath>C:\Program Files\Java\jre6/../lib/tools.jar</systemPath>
      <optional>true</optional>
    </dependency>

Solution 14 - Java

Add this dependecy in pom.xml file. Hope this help.
In <systemPath> property you have to write your jdk lib path..

    <dependency>  
          <groupId>com.sun</groupId> 
           <artifactId>tools</artifactId>
        <version>1.4.2</version>
        <scope>system</scope>
        <systemPath>C:/Program Files/Java/jdk1.6.0_30/lib/tools.jar</systemPath>
        </dependency> 

Solution 15 - Java

Ended up using eclipse.ini fix:

openFile
-vm (Your Java Home JDK here)

For example, -vm C:\Java\JDK\1.6.

Had to also change JRE to JDK:

In Eclipse IDE go to:

  1. Window -> Preferences -> Installed JREs
  2. Click on Add (to locate new JRE)
  3. Select standard JVM -> next
  4. Click on Directory to locate JRE home, put JDK_INSTALL_LOCATION and finish.
  5. Go to your java project's Properties -> Java build Path -> Libraries -> select JRE -> Edit -> select Workspace default JRE -> finish
  6. Do a full workspace cleanup with project -> clean.

Solution 16 - Java

As other posters have stated the issue here has to do with the JRE that eclipse is using not being able to find the tools jar. I solved the issue by going in a bit of a different direction than what was stated above, and it was because of the way that my projects and environment.

Eclipse 4.5 requires at least Java 7 for runtime, so I've got my system setup to use a Java 8 JRE located at C:\java\jre1.8.0_45.

Next, I'm using a POM file that assumes that I'm running with a Java 6 JDK.

  <profiles>
    <profile>
      <id>default-profile</id>
      <activation>
        <activeByDefault>true</activeByDefault>
        <file>
          <exists>${java.home}/../lib/tools.jar</exists>
        </file>
      </activation>
      <properties>
        <toolsjar>${java.home}/../lib/tools.jar</toolsjar>
      </properties>
    </profile>
    <profile>
      <id>osx_profile</id>
      <activation>
        <activeByDefault>false</activeByDefault>
        <os>
          <family>mac</family>
        </os>
      </activation>
      <properties>
        <toolsjar>${java.home}/../Classes/classes.jar</toolsjar>
      </properties>
    </profile>
  </profiles>

  <dependencies>
    <dependency>
      <groupId>com.sun</groupId>
      <artifactId>tools</artifactId>
      <version>1.6.0</version>
      <scope>system</scope>
      <systemPath>${toolsjar}</systemPath>
    </dependency>
  </dependencies>

I'm not allowed to change the POM file, so I had to do some jiggery pokery. I copied the tools.jar from my Java 6 JDK, created the directory C:\java\lib and pasted it there. I then restarted eclipse and cleaned my project. And VOILA errors are gone.

It's not an elegant solution, and I would think that the proper solution would be to change the way the POM is setup, but as I was not able to, this works.

Solution 17 - Java

I had the same problem on a Windows 7 and Eclipse 3.7 I managed to fix it by starting

>eclipse.exe -vm "D:\JDK6\bin"

You can start a cmd and launch eclipse like that, or you can edit your shortcut and add -vm "D:\JDK6\bin" as an argument in the "target section".

As a sidenote, I also tried to add -vm "D:\JDK6\bin" to eclipse.ini but did not work. And adding JRE6 will not work since it does NOT contain tools.jar in it's "lib" directory. Only JDK does.

Solution 18 - Java

After trying out all the above I was still having the same issue.

  • PATH environment variable point to JDK 1.7\bin
  • My JAVA_HOME environment variable was pointed to the JDK 1.7
  • My eclipse.ini had the javaw -vm entry pointing to JDK 1.7
  • My eclipse preference had JDK 1.7 as the installed JRE.
  • My project build path was using JDK 1.7.

Then I tried the following,

  • Open a command prompt and typed java -version. It showed me a JRE version 1.8.

  • Open a command prompt and went to location of the JDK 1.7 bin directory and typed java -version. This time it showed correctly 1.7.

Then after digging at few places I found that apart from the above locations there are additional locations for Java runtime.

Registry

There is also a registry key where JRE location are specified under > HKLM\Software\Javasoft\Version

I changed the entries here to point to the JDK 1.7

ProgramData

The directory "C:\ProgramData\Oracle\Java\javapath" is present in PATH environment variable and contains shortcuts to the java, javaw etc... The target for these shortcuts were all JRE 1.8. (This I think was the main problem) I changed the shortcuts to point to the correct JDK exe's.

Once all of this was done. I opened eclipse all the jdk.tools pom.xml errors disappeared.

Solution 19 - Java

I got this problem and it turns out that JBossDevStudio 9.1 on Windows is a 32-bit program. Eclipse, and thus the JBossDevStudio, does not work with the wrong type of JVM. 64-bit eclipse needs a 64-bit JVM, 32-bit eclipse needs a 32-bit JVM. Thus configuring Eclipse to run with my installed 64-bit JDK did not work.

Installing a 32 bit JDK and running Eclipse from that solved the problem.

At least for one of my projects, an other where I had tried to configure a runtime JDK in the Eclipse project properties is still broken.

Solution 20 - Java

I solved the problem by uninstalling JRE from my system and leaving JDK only. Reinstall JDK is not enough because Oracle JDK installer installs both JDK and JRE

BTW, it seems to me that this bug is responsible for troubles: java.home of the Eclipse JRE is used instead of the build JRE

Solution 21 - Java

In my case, I was executing Maven Build from Eclipse Run Configurations. Even after changing the default JRE configuration to point to JDK installation folder, the issue didn't get fixed for me. The reason is that there is a JRE tab in the Maven Build - Run Configuration (see the image below). And it was still pointing to my JRE installation. I changed it to point to JDK installation and then ran the Maven Build. This time, it worked. enter image description here

Solution 22 - Java

Let's understand why this issue happened:

> $ mvn -version >> Apache Maven 3.6.1 (d66c9c0b3152b2e69ee9bac180bb8fcc8e6af555; 2019-04-04T20:00:29+01:00) Maven home: C:\Program Files\Apache\maven-3.6.1 Java version: 1.8.0_221, vendor: Oracle Corporation, runtime: C:\Program Files\Java\jre1.8.0_221 Default locale: en_GB, platform encoding: Cp1252 OS name: "windows 10", version: "10.0", arch: "amd64", family: "windows"

Maven "mvn -version" command returns above output.

We can see maven gets the java runtime path as "C:\Program Files\Java\jre1.8.0_221" if you don't specify JAVA_HOME environment variable. And then maven assumes this path to be JAVA_HOME. That's why when building the application either from command prompt or any IDE, maven looks for tools.jar file in path "%JAVA_HOME%..\lib\tools.jar".

tools.jar is present in JDK path, so we need to mention this to maven before using it. Now a days machines are build with already available jre, but jdk is only required for development. This might be the reason why maven picks jre path automatically.

For more help, please read the code mvn.cmd available in maven installation path.

Solution 23 - Java

Problem is system is not able to find the file tools.jar

So first check that the file is there in the JDK installation of the directory.

enter image description here

Make the below entry in POM.xml as rightly pointed by others

<dependency>
<groupId>com.sun</groupId>
<artifactId>tools</artifactId>
<version>1.6</version>
<scope>system</scope>
<systemPath>C:\Program Files\Java\jdk1.8.0_241\lib\tools.jar</systemPath>
</dependency> 

then Follow the below steps also to remove the problem

  1. Right Click on your project

  2. Click on Build path

As per the below image, select the workspace default JRE and click on finish.

enter image description here

Solution 24 - Java

Changing 'Installed JREs' under 'Preferences -> Java -> Installed JRE' to JDK home worked for me.

FYI - Am using JDK 1.8.

Solution 25 - Java

I believe these local patches will work. However these likely to cause downstream deployment issues. I simply downloaded a new version of Eclipse with Java 11, now everything works fine.

Solution 26 - Java

Another scenario

  • The JAVA_HOME variable must point to a Java 11+ installation.
  • Maven is used in old projects. New projects use Gradle.
  • Old maven projects use Java 8 and some of them break with the missing tools.jar file error if we use Java 9+.

A solution

  • Edit the mvn shell script (mvn.bat or mvn.cmd on Windows) and set JAVA_HOME to point to a JDK 8 installation.
  • The script is in the /bin directory under your apache maven installation.
  • Example of where to set the variable (Windows script):
    @REM ==== START VALIDATION ====
    set JAVA_HOME=C:\Program Files\Java\jdk1.8.0_161
    

Solution 27 - Java

Changing the relative location of ${java.home}/../lib/tools.jar to the absolute path of C:\Program Files\Java\jdk1.6.0_29\lib\tools.jar works for me.

You should only have to change it in the playn/pom.xml.

Now for the playn-samples, Vladiator is right, that's too many pom files to change.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionboldinventionsView Question on Stackoverflow
Solution 1 - JavaKanmuriView Answer on Stackoverflow
Solution 2 - JavaCristian ColoradoView Answer on Stackoverflow
Solution 3 - JavaDennyView Answer on Stackoverflow
Solution 4 - JavaeisView Answer on Stackoverflow
Solution 5 - JavaJakub AdamekView Answer on Stackoverflow
Solution 6 - JavaSealsixView Answer on Stackoverflow
Solution 7 - Javaarunkumar sambuView Answer on Stackoverflow
Solution 8 - JavaOlivierView Answer on Stackoverflow
Solution 9 - JavaRohit KumarView Answer on Stackoverflow
Solution 10 - JavaSHIVANSH NARAYANView Answer on Stackoverflow
Solution 11 - JavaconditView Answer on Stackoverflow
Solution 12 - Javauser1140969View Answer on Stackoverflow
Solution 13 - JavaVladiat0rView Answer on Stackoverflow
Solution 14 - JavaDivyang PatelView Answer on Stackoverflow
Solution 15 - JavaahaamanView Answer on Stackoverflow
Solution 16 - JavaRick Velilla IIView Answer on Stackoverflow
Solution 17 - Javajumping-jackView Answer on Stackoverflow
Solution 18 - JavaAsh RView Answer on Stackoverflow
Solution 19 - JavaSamuel ÅslundView Answer on Stackoverflow
Solution 20 - JavamichaldoView Answer on Stackoverflow
Solution 21 - Javadk4softwareView Answer on Stackoverflow
Solution 22 - JavaSambit SwainView Answer on Stackoverflow
Solution 23 - JavaGaurav KhuranaView Answer on Stackoverflow
Solution 24 - JavaLarsenView Answer on Stackoverflow
Solution 25 - JavaCocu_1012View Answer on Stackoverflow
Solution 26 - JavaPaulo MersonView Answer on Stackoverflow
Solution 27 - JavaJDBertronView Answer on Stackoverflow