linux unable to locate tools.jar,Unable to locate tools.jar

可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):

问题:

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.

回答1:

Yes, you've downloaded and installed the Java Runtime Environment (JRE) instead of the Java Development Kit (JDK). The latter has the tools.jar, java.exe, javac.exe, etc.

回答2:

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 . 05/08/2012 09:43 AM .. 05/08/2012 09:46 AM jdk1.7.0_04 05/08/2012 09:19 AM jre6 05/08/2012 09:44 AM 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.

回答3:

Install the Java SDK.

Add a System Environment Variable called JAVA_HOME with the value of JDK location.

Go to Control Panel\System and Security\System. Advanced System Settings, Environment Variables, System Variables, New... Example:

Variable Name:JAVA_HOME

Variable Value: C:\Program Files\Java\jdk1.7.0_21

Close/reopen your CMD window so that the new variable takes effect before attempting to re-run the ant command.

回答4:

I had the same problem and copying C:\Program Files\Java\jdk1.6.0_26\lib\tools.jar to C:\Program Files\Java\jre6\lib\ext worked for me

回答5:

Set your JAVA_HOME environmental variable to point to C:\Program Files\Java\jdk1.7.0_02.

回答6:

If you are in Linux you can solve this by installing java on the system: sudo apt-get install openjdk-7-jdk openjdk-7-jre

回答7:

No, according to your directory structure, you have installed a JRE, not a JDK. There's a difference. C:\Program Files\Java\jre6\lib ^^^^

It should be something like: C:\Program Files\Java\jdk1.6.0_24

回答8:

Don't spend too much time looking for tools.jar. If you get an error like that, don't be upset.

If you already have java JDK 1.5, go to your lib folder, and the tools.jar should be available there. Copy and paste it in your ant bin folder, then try to use the command ant -version.

You should see the expected result.

回答9:

go to your jdk path where you installed your java

For e.g In my PC JDK installed in the following path

"C:\Program Files\Java\jdk1.7.0_17\";

After go to the lib folder e.g "C:\Program Files\Java\jdk1.7.0_17\lib"

in the lib directory there is tool.jar file

Copy this file and past it in the lib forlder of jre7 directory for e.g

"C:\Program Files\Java\jre7\lib"

回答10:

I had the same issue on a linux machine. I was quite frustrated at first, because I have installed both the JDK and JRE. I am using version 1.6, 1.7 and 1.8 simultaneously, and I have played a lot with the alternatives to have everything set properly.

The problem was quite stupid to solve, yet counter-intuitive. While I was using the correct JDK, I paid attention to the path of the tools jar maven complained about - it was expecting it to be $JAVA_HOME\..\lib\tools.jar

The $JAVA_HOME variable pointed directly to my jdk folder (/usr/local/java which was also the correct $PATH entry and alternative sym link). It actually searches for the lib folder outside the java directory, because: $JAVA_HOME\..\lib\tools.jar

will resolve to /usr/local/lib/tools.jar

and that is not a valid location.

To solve this, the $JAVA_HOME variable should instead point to this location /usr/local/java/jre (assuming the JDK path is /usr/local/java) -- there is actually jre folder inside the JDK installation directory, that comes with each JDK. This new setup will cause maven to look at the JRE directory, that is part of the JDK: $JAVA_HOME\..\lib\tools

which now resolves to /usr/local/java/jre/../lib/tools.jar

and finally to /usr/local/java/lib/tools.jar

which is where the tools.jar really resides.

So, even of you are indeed using the JDK instead of the JRE, the $JAVA_HOME has to point to the JRE. Remember, the OS alternative should still refer to the JDK.

回答11:

I had the same problem even after installing Java JDK and set JAVA_HOME to ..\jdk1.6.0_45\bin folder.

Ant is still trying to find tools.jar in C:\Program Files\Java\jre6\lib folder.

I've fixed it by adding JAVACMD environment variable and set path for it to java.exe in the jdk folder.

In my case it was C:\Program Files\Java\jdk1.6.0_45\bin\java.exe

回答12:

In eclipse window> preferences>Java> Installed JRE, I pointed the directory to the jre directory in the jdk 1.7 and i worked file for me e.g C:\Program Files\Java\jdk1.7.0_71\jre

回答13:

I had my JDK_path (C:\Program Files\Java\jdk1.7.0_79) in my JAVA_HOME and also the JDK_path\bin in my PATH. But, still my ant was using the JRE instead of JDK.

The issue was I had C:\ProgramData\Oracle\Java\javapathbefore my JDK_path in PATH variable. I simply moved my JDK_path before the oracle one and the issue solved.

回答14:

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.

回答15:

You may face similar problem on Ubuntu: Embedded error: tools.jar not found: /usr/lib/jvm/java-7-openjdk-amd64/jre/../lib/tools.jar

The problem is with JAVA_HOME that is not set properly.

So, on Ubuntu 14.04 x64 using Java8: sudo apt-get install openjdk-8-jdk openjdk-8-jre export JAVA_HOME=/usr/lib/jvm/java-8-openjdk-amd64

回答16:

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

回答17:

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

回答18:

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

if you have installed jdk then

..Java/jdkx.x.x

folder must exist there so in stall it and give full path like C:\Program Files\Java\jdk1.6.0\lib\tools.jar

回答19:

Make sure that your classpath is set correctly and pointing to the correct version of the JDK that you have installed. Also, are you using Open JDK? I have had this issue before after I tried to move from open JDK to Suns JDK. This is an example of how that issue could be fixed.

回答20:

maven-compiler-plugin use jdk ,not jre, tools.jar is in C:\Program Files\Java\jdk1.6.0\lib\tools.jar you must config project JRE System Libary with jdk,not jar. This is the simplest solution.

回答21:

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

回答22:

solving this problem I have simply copied the tools.jar file from C:\Program Files\Java\jre1.8.0_112\lib to C:\Program Files\Java\jdk1.8.0_112\lib so that I have two tools.jar files instead of one and problem disappeared.

回答23:

For me what's working: I downloaded an old version of Java 1.7

I actually set my JAVA_HOME from C:/program files X86/Java BUT after I installed the 1.7 version I had another Java in program files/Java. And at this moment I found the tools.jar here. Then I changed for this new path and it's working

回答24:

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.

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值