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 15:55

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

查看更多
宁负流年不负卿
3楼-- · 2019-01-01 15:55

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.

查看更多
柔情千种
4楼-- · 2019-01-01 15:57

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.

查看更多
若你有天会懂
5楼-- · 2019-01-01 15:57

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.

查看更多
路过你的时光
6楼-- · 2019-01-01 15:58

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.

查看更多
柔情千种
7楼-- · 2019-01-01 15:59

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.

查看更多
登录 后发表回答