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?
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.
For anyone who stumbles over this issue in the future, read on for a more elegant solution:
This issue crops up in one of the two scenarios:
You do not have JDK installed and configured; or
You've both JDK and JRE installed and JRE is getting precedence over the JDK path.
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>
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
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>
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
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With