Missing artifact com.sun:tools:jar
Asked Answered
D

27

118

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>
Delta answered 4/12, 2011 at 12:54 Comment(7)
Do you get same error running maven from command-line?Ocher
I added the pom.xml file. I apologize for not knowing how to do anything with maven using the command line.Delta
POM is broken. Missing mandatory tags such as groupId, artifactId, version... The parent POM is also module version that does not exist in Maven central....Wellbred
did you fixed it somehow? none of this seem to work for me (Windows7-64 bit - jdk1.6)Lammers
As this is a common issue, could you accept an answer that worked for you?Cyder
Quick solution which helped me was to point the JRE to the one available in the JDK folder.Issuable
Had a similar issue when running a robot framework testcase in eclipse neon (4.6.3). Under Window/Preferences/Java/Installed JRE's changed JRE to JDK and that worked for me. As correctly pointed out above, the JDK does include the tools.jar.Schoenberg
A
61

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.

Agglutinogen answered 18/1, 2012 at 17:44 Comment(6)
This worked for us in Windows 7. We had to modify the shortcut to add the -vm "..." argument rather than using eclipse.ini. Also, we had to re-import our maven project into the workspace before the error would go away.Reside
Same here - no dice with .ini, but the -vm arg in the cmdline worked.Cyder
I edited the answer to explain how to change eclipse.init. Source: wiki.eclipse.org/Eclipse.ini#-vm_value:_Windows_ExampleKnelt
Same here - adding -vm to shortcut has worked for me. I haven't have to reimport my project, it's been enough to project/maven/update it.Analyse
To let it work, I needed tot add javaw.exe to that path as well (so in full: -vm "T:\Program Files\Java\jdk1.8.0_66\bin\javaw.exe");Storehouse
I had to do mvn update to make it working after adding vm args to shortcut.Yenta
S
32

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:

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>
Shayneshays answered 1/9, 2012 at 20:3 Comment(2)
Hint: use 'mvn dependency:tree' to find where to insert your exclusion.Boccie
Adding the exclusions tag in pom.xml doesn't work for me.Debauchee
C
28

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.

Copra answered 6/12, 2011 at 5:33 Comment(5)
I highly suggest not doing this - it solves the problem but is not portable to other developers or to build environments. See the other answers, they seem to do the trickCyder
maybe it's better change the systemPath to <systemPath>${java.home}/lib/plugin.jar</systemPath>Edge
#3080937 has how to do this in a portable way.Freshwater
I mad change my pom.xml like this (force newer version of java-md-doclet) the error disappears: <dependencyManagement> <dependencies> <dependency> <groupId>com.github.iotaledger</groupId> <artifactId>java-md-doclet</artifactId> <version>2.1.3</version> </dependency> </dependencies> </dependencyManagement>Tia
How can we write same path for MacBruis
A
28

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.

Abundance answered 30/9, 2015 at 16:54 Comment(3)
Worked for me, issue arose upgrading a java 6 codebase to java 8Trainband
I've identified the spotbugs-maven-plugin as my culprit, thanks!Glaucescent
note to me in history: without eclipse, you can use mvn dependency:tree and grep to find the dependencyAbundance
B
10

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.

Bonanno answered 10/3, 2013 at 18:22 Comment(2)
Note to future me: this has to be before -vmargs line, as anything past that will be interpreted as VM startup args. So: right before that one!Abundance
This solution using -vm before the -vmargs is the key!. Thank you!Boehmenism
D
9

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
Discussion answered 19/3, 2021 at 11:57 Comment(0)
M
6

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)

Misprint answered 4/10, 2013 at 12:30 Comment(0)
H
6

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>
Handel answered 7/9, 2016 at 9:23 Comment(0)
F
5

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.

Fleischer answered 5/3, 2020 at 15:46 Comment(0)
P
4

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

if I want to use java version 1.8.0_261:

export JAVA_HOME=`/usr/libexec/java_home -v 1.8.0_261`
Pyrography answered 16/11, 2020 at 2:48 Comment(1)
This worked for me on mac os big sur in 2021.Pinchas
J
3

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
Jarietta answered 25/3, 2014 at 0:37 Comment(0)
F
3

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>
Finedraw answered 8/5, 2018 at 13:41 Comment(0)
M
1

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>
Machicolation answered 24/12, 2011 at 1:28 Comment(0)
O
1

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> 
Osteoblast answered 12/7, 2013 at 7:12 Comment(0)
P
1

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.
Politic answered 22/8, 2013 at 11:48 Comment(1)
All of our Windows instances of Eclipse IDE have this issue. All Ubuntu based Eclipse IDEs aren't affected for us. So, we used this method on the Windows instances and it fixes our issues. Make sure to add a line break after -vm, put the Java SDK path on the nect line, and place all of the newly added -vm flag before the --vmargs in the eclipse.ini file.Offoffbroadway
W
1

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.

Winner answered 30/7, 2015 at 14:42 Comment(0)
F
0

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.

Flywheel answered 3/9, 2012 at 16:31 Comment(0)
L
0

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.

Lamson answered 5/4, 2016 at 4:10 Comment(0)
U
0

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.

Unarm answered 27/4, 2016 at 8:33 Comment(0)
D
0

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

Diazole answered 20/2, 2017 at 13:28 Comment(0)
O
0

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

Obligation answered 15/3, 2018 at 9:30 Comment(0)
V
0

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.

Vespine answered 29/8, 2019 at 14:3 Comment(0)
D
0

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

Droshky answered 22/1, 2020 at 10:5 Comment(0)
G
0

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

FYI - Am using JDK 1.8.

Gong answered 7/5, 2020 at 7:36 Comment(0)
S
0

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.

Secede answered 19/5, 2021 at 21:7 Comment(0)
N
0

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
Nolin answered 20/7, 2021 at 17:14 Comment(0)
W
-1

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.

Warlock answered 9/1, 2012 at 0:53 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.