Ant needs tools.jar and unable to find it

好久不见. 提交于 2019-12-02 15:45:41

It's there on my machine. I'm running Sun JDK 1.6.0_21 on Windows XP SP3.

Are you sure you have the JDK? Is it possible that you only have the JRE?

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

Note: On CentOS / RHEL installing java-1.x.0-openjdk will not be enough. Also install java-1.x.0-openjdk-devel.

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

apt install defalut-jdk # this doesn't contain some file, like tools.jar...
apt install openjdk-8-jdk # this contains all files.

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

..and you can always search for all available versions with

$ sudo apt-cache search openjdk | grep ^openjdk

From the website https://openjdk.java.net/install/ we can read

The openjdk-7-jre package contains just the Java Runtime Environment. If you want to develop Java programs then install the openjdk-7-jdk package.

Try the following:

% sudo apt-get install sun-java6-jdk

% sudo update-alternatives --config java

select the option that has the path

/usr/lib/jvm/java-6-sun/jre/bin/java

Worked for me on an ubuntu 10.4

u can try to put your JAVA_HOME also, as follows:

% sudo export JAVA_HOME=$(readlink -f /usr/bin/javac | sed "s:/bin/javac::")

Installing the jdk-6u45-linux-x64.bin (from the oracle.com site) via unzip does not result in a tools.jar. I guess that file is created by the "make-jpkg" script. Once I did that, and installed the resulting .deb file, everything was fine. I really hate oracle's lawyers.

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

On Ubuntu I've fixed this problem by installing package

openjdk-7-jre-lib

tools.jar appeared after that.

(I know this is an old post, but comment in hope that it will be helpful for somebody lurking for answer like I was today.)

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!