Ant needs tools.jar and unable to find it

2019-03-08 10:17发布

I am putting together a dev environment for a Java program and after the first try of my Ant build scripts I got this error:

Unable to locate tools.jar. Expected to find it in /usr/lib/jvm/java-6-openjdk/lib/tools.jar

While the path to the jdk is correct, the tools.jar really wasn't there. Is it actually supposed to be there or did I get some config/installation thing wrong?

10条回答
虎瘦雄心在
2楼-- · 2019-03-08 10:51

It seems like you can have Java installed in /usr/lib/jvm/java-6-openjdk but only have the JRE, not the JDK. This fixed it for me:

sudo apt-get install openjdk-6-jdk

查看更多
Bombasti
3楼-- · 2019-03-08 10:51

Even if you have jdk installed, you'll need to redirect JAVA_HOME to point to it.

Here's one weird trick you can put into your .profile to set JAVA HOME properly, no matter which java you have:

export JAVA_HOME=$(dirname $(dirname $(readlink -e /usr/bin/java)))
# Test for jdk installed above jre
if [ -x $JAVA_HOME/../bin/java ]; then export JAVA_HOME=$(dirname $JAVA_HOME); fi
查看更多
我想做一个坏孩纸
4楼-- · 2019-03-08 10:54

On Debian, after installing Ant with apt-get install ant, I've encountered the same error when running it:

Unable to locate tools.jar. Expected to find it in /usr/lib/jvm/java-6-openjdk-amd64/lib/tools.jar

Indeed, there's no mention of any tools.jar anywhere in /usr/lib, although /usr/lib/jvm/java-6-openjdk-amd64 itself does exist.


https://packages.debian.org/search?searchon=contents&keywords=java-6-openjdk-amd64%2Flib%2Ftools.jar

As per the search above, java-6-openjdk-amd64/lib/tools.jar appears to be part of openjdk-6-jdk, which indeed didn't get installed with ant (since it's only marked as suggested (https://packages.debian.org/wheezy/ant)).

apt-get install openjdk-6-jdk

查看更多
一夜七次
5楼-- · 2019-03-08 10:55

On Ubuntu I've need to install JDK sudo apt-get install openjdk-7-jdk

查看更多
登录 后发表回答