34

I think I know how to solve the problem except: I don't know where in the pom the specific version is referred to (I do not see it explicitly) and the solution I have seen is to add this dependency:

<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 I would like to use com.oracle and the jdk directory on Windows is jdk1.8.

So is there a way to make the pom "want" the version of tools that I actually have on my machine?

Jeff
  • 1,513
  • 4
  • 18
  • 34
  • how maven can guess what version u have on your machine? – OhadR Mar 22 '15 at 14:06
  • I don't know what is making it ask for 1.6. I have the tools.jar file under the latest version of java but when I specify that dependency, the pom still shows an error. The error (big red circle) occurs at the top of the pom -- it is not associated with the dependency block. – Jeff Mar 22 '15 at 14:19
  • I've never faced such issue, so this is just a guess: are you sure you're working with a jdk, and it's not that a jre is being called instead? – watery Mar 22 '15 at 19:09
  • can u paste here your pom? and the exact error? – OhadR Mar 22 '15 at 20:10
  • Does this answer your question? [Missing artifact com.sun:tools:jar](https://stackoverflow.com/questions/8375423/missing-artifact-com-suntoolsjar) – Olivier Mar 06 '20 at 08:53

9 Answers9

45

I finally tackled this the proper way.

This happens when eclipse is launched with the JRE instead of the JDK as tools.jar isn't in the JRE. Based on that assertion, try installing the JDK. If it's already installed, check in your Path that you have the JDK path and not the JRE path.

Be careful, the latest versions of java seems to add in the Path the following directory: C:\ProgramData\Oracle\Java\javapath. It contains shortcuts that may link to the JRE. You'll want to remove that and add in the link to your JDK bin folder. (e.g. C:\Program Files\Java\jdk1.8.0_66\bin)

Note that you may need to restart your computer for the changes in the Path to be effective for the eclipse launch (I don't really understand why I had to but I did).

Also note that Java updates will probably re-add the javapath to your PATH. So you may want not to use auto-updates but instead manually update your JDK and adapt your path after the install. It's a bit heavy but does the work.

Crystark
  • 3,693
  • 5
  • 40
  • 61
  • 1
    I had to also delete copies of the JRE .exes in `c:\windows\system32`. Doesn't feel good but whatever to get bloated Eclipse/MavenCrapWare to work. – makhdumi Dec 02 '16 at 17:45
27

For anyone who stumbles over this issue in the future, read on for a more elegant solution:

Reason

This issue crops up in one of the two scenarios:

  1. You do not have JDK installed and configured; or

  2. You've both JDK and JRE installed and JRE is getting precedence over the JDK path.

Solution

As explained in this link by the team at 'Hadoop in the real world', you merely need to add the dependency to tools.jar in your pom.xml file.

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

If the error persists, then just change the path to tools.jar to an absolute path as shown below:

<systemPath>C:/Program Files/Java/jdk1.8.0_65/lib/tools.jar</systemPath>
Community
  • 1
  • 1
Vikram Deshmukh
  • 12,304
  • 4
  • 36
  • 38
  • 1
    the system path did it for me in eclipse. – Ares Nov 08 '18 at 16:09
  • @VikramDeshmukh: We are now in the "future" and the problem might actually be the JDK version. See my answer [here](https://stackoverflow.com/a/60560378/7009806). – Olivier Mar 06 '20 at 08:46
4

As I figured the best way to tackle this is to add the following configuration to your eclipse.ini to make sure it uses the jdk copy of javaw while running eclipse instead of the JRE copy which solves the problem and seems to be the correct approach to fix the issue

-vm
C:/Program Files/Java/jdk1.8.0_73/bin/javaw.exe
Gautam
  • 1,030
  • 13
  • 37
  • 1
    I think an issue with this is how someone checking out the project will get this. I think therefore the pom is the right place to address the problem. – Jeff Apr 21 '17 at 22:43
  • 1
    the issue with addressing it in the pom is that the user checking out the project is anyway expected to use the jdk copy of javaw and not jre. so I think this is better solved through convention rather then configuration. – Gautam Aug 14 '17 at 04:44
  • @Jeff In addition each individual user will have a distinct path to the jar file in question and thus will not be able to run the build as it is using the maven config. Also modifying the pom this way will make the POM no more SCCS friendly. e.g. we use a mix of Mac / Unix / Windows environments and thus the path in question changes from user to user. Although using the java.home env variable can be a solution to this problem. – Gautam Jun 26 '18 at 06:27
3

you merely need to add the dependency to tools.jar in your pom.xml file.

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

If the error persists, change the path to tools.jar to an absolute path as shown below:

<systemPath>C:/Program Files/Java/jdk1.8.0_65/lib/tools.jar</systemPath>
2

You can use the "java.home" environment variable :

<dependency>
   <groupId>com.sun</groupId>
   <artifactId>tools</artifactId>
   <version>1.6</version>
   <scope>system</scope>
   <systemPath>${java.home}/lib/tools.jar</systemPath>
</dependency>

Please have a look to : https://maven.apache.org/guides/introduction/introduction-to-dependency-mechanism.html#System_Dependencies

dosyfier
  • 318
  • 2
  • 8
  • My question is, why is the error referring to the absence of version 1.6 tools.jar? I have a much more recent (1.8) version of this file and I would like to be able to use it. – Jeff Mar 22 '15 at 14:52
  • Sorry, I misunderstood. The 1.6 version may come out of the JDK version referenced in your JAVA_HOME env variable. Is your JAVA_HOME defined with the JDK 1.8 path? What about your IDE? Are you getting this error outside or within your IDE? Perhaps your IDE isn't using the JDK version you expect? – dosyfier Mar 23 '15 at 12:56
2

I figured out the solution to this problem in eclipse.

In Eclipse,

Navigate to Window -> Preferences

On the left hand pane, expand Java and you will find the "Installed JREs" entry

Select that and you should be able to see the JRE entry that is referring to the JRE folder rather than the JDK folder.

Select the entry to edit it and then redirect it to the JDK folder and click on Apply.

This solved my problem right away.

Mithun B
  • 21
  • 1
2

Add this code to the dependencies pom.xml:

<dependency>
   <groupId>org.apache.solr</groupId>
   <artifactId>solr-core</artifactId>
   <version>4.5.1</version>
   <exclusions>
      <exclusion>
         <artifactId>jdk.tools</artifactId>
         <groupId>jdk.tools</groupId>
      </exclusion>
   </exclusions>
</dependency>
1

For the benefit of those who Google this error when encountering it in 2021 (many years after the OP... yikes) and are using a modern openjdk distribution, it is possible to exclude jdk.tools from individual dependencies like so:

<dependency>
    <groupId>org.apache.systemds</groupId>
    <artifactId>systemds</artifactId>
    <version>2.1.0</version>
    <exclusions>
        <exclusion>
            <artifactId>jdk.tools</artifactId>
            <groupId>jdk.tools</groupId>
        </exclusion>
    </exclusions>
</dependency>

Admittedly I'm not sure of the general consequences of this, but it is useful in the situations I've needed it (e.g. when running mvn dependency:copy-dependencies)

Liam Deacon
  • 904
  • 1
  • 9
  • 25
0
<dependency>
    <groupId>jdk.tools</groupId>
    <artifactId>jdk.tools</artifactId>
    <version>1.7</version>
    <scope>system</scope>
    <systemPath>C:/jdk1.7.0_51/lib/tools.jar</systemPath>
</dependency>
smita
  • 1