Unable to locate tools.jar

2019-01-01 15:22发布

I am building a project in Java.

I have this error:

Unable to locate tools.jar. Expected to find it in C:\Program Files\Java\jre6\lib\tools.jar

I have installed a JDK and the folder: C:\Program Files\Java\jre6\lib is in my system but the file tools.jar is not there.

27条回答
情到深处是孤独
2楼-- · 2019-01-01 16:07

I was also facing the same error. This was removed after setting Java_Home path to C:\Program Files\Java\jdk1.8.0_121. Please ensure bin is not included in the path and no slash is there after jdk1.8.0_121 after you have defined %JAVA_HOME%\bin in the system path variable.

查看更多
临风纵饮
3楼-- · 2019-01-01 16:10
  • Right click on your ant file
  • Go to "Run as" then click on "Ant Build..."
  • Go to the "JRE" tab
  • Select a JDK and not a JRE
查看更多
忆尘夕之涩
4楼-- · 2019-01-01 16:11

Make sure that both the %JAVA_HOME% and %JAVA_HOME%/bin paths are added to your PATH variable.

All the answers about copying tools.jar into the correct position is a poor idea at best.

Make sure that your IDE can find these jars the way it was designed and intended for.

查看更多
笑指拈花
5楼-- · 2019-01-01 16:13

In case this is still an issue for anyone, I have a bit of clarification on the previous answers. I was running into this same issue using ant with only a JDK installed. Although, the JDK installer gave me a directory structure like this:

 Directory of C:\Program Files\Java

05/08/2012  09:43 AM    <DIR>          .
05/08/2012  09:43 AM    <DIR>          ..
05/08/2012  09:46 AM    <DIR>          jdk1.7.0_04
05/08/2012  09:19 AM    <DIR>          jre6
05/08/2012  09:44 AM    <DIR>          jre7
               0 File(s)              0 bytes

and when I ran ant, it complained about not finding tools.jar under the jre7 subdirectory. It wasn't until I set "JAVA_HOME=C:\Program Files\Java\jdk1.7.0_04" that the error went away.

查看更多
零度萤火
6楼-- · 2019-01-01 16:13

it has been solved with me in windows os by setting the JAVA_HOME variable before running as follows:

set JAVA_HOME=C:\Program Files\Java\jdk1.8.0_111

查看更多
浮光初槿花落
7楼-- · 2019-01-01 16:13

If you have installed JDK 9.0.1 you will also have this problem as the tools.jar has been deprecated. See migration document.

查看更多
登录 后发表回答