可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
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>
回答1:
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.
回答2:
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>
回答3:
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.
回答4:
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:
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.
回答5:
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.
回答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)
回答7:
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>
回答8:
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
回答9:
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>
回答10:
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>
回答11:
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>
回答12:
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.
回答13:
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:
- Window -> Preferences -> Installed JREs
- Click on Add (to locate new JRE)
- Select standard JVM -> next
- Click on Directory to locate JRE home, put JDK_INSTALL_LOCATION and finish.
- Go to your java project's Properties -> Java build Path -> Libraries -> select JRE -> Edit -> select Workspace default JRE -> finish
- Do a full workspace cleanup with project -> clean.
回答14:
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.
回答15:
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.
回答16:
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.
回答17:
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
回答18:
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
回答19:
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.
回答20:
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.
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.
回答21:
If you are using the openjdk then you need to install the openjdk-6-sdk package.
回答22:
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.