Ant needs tools.jar and unable to find it
Asked Answered
C

10

48

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?

Canady answered 5/4, 2011 at 23:50 Comment(3)
It looks like you have JRE-only Java installed. See openjdk.java.net/install perhaps. What OS do you have there?Samaria
OS is Ubuntu. At first I installed only JRE then I installed JDK. They could possibly be mis-configured :)Canady
possible duplicate of Unable to locate tools.jarPlath
T
14

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?

Thromboembolism answered 5/4, 2011 at 23:54 Comment(5)
I have both, jdk and jre. but that particular directory got downloaded and extracted as jdk which makes me assume it is jdk lol.Canady
To be more specific, add this to .bashrc export JAVA_HOME=/usr/binNomarchy
To be yet more specific, if you're running a build script that invokes an Ant build, you may need to actually set the export in your ~/.bashrc. I found just doing it in the terminal before running one particular build.sh didn't solve the problem. I also set export JAVA_HOME=/usr/lib/jvm/java-7-openjdk-amd64 rather than just /usr/; JAVA_HOME should be the install directory of the JDK, since Ant will (I think) look in JAVA_HOME/bin and JAVA_HOME/lib.Casease
How can this be the accepted answer? It's not even an answer, per se.Santiago
I was just thinking the smae as @HeathHunnicutt, it seems everywhere I go to find answers to this question I'm met with "you must only have JRE installed" I know I have /usr/lib/jvm/java-11-openjdk-amd64/ so wtfOkie
T
66

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

Takeo answered 18/9, 2013 at 16:55 Comment(3)
You'll also need to redirect JAVA_HOME to point to the jdk and not the jre.Miley
Also works for java 8: sudo apt-get install openjdk-8-jdkDelinquent
Isn't this a bug in Ubuntu then? Shouldn't the ant package depend on the JDK?Ore
A
19

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

Autism answered 19/12, 2013 at 15:44 Comment(1)
thanks, I wonder why a jdk which is a java developer kit requires an extra devel package....Christos
T
14

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?

Thromboembolism answered 5/4, 2011 at 23:54 Comment(5)
I have both, jdk and jre. but that particular directory got downloaded and extracted as jdk which makes me assume it is jdk lol.Canady
To be more specific, add this to .bashrc export JAVA_HOME=/usr/binNomarchy
To be yet more specific, if you're running a build script that invokes an Ant build, you may need to actually set the export in your ~/.bashrc. I found just doing it in the terminal before running one particular build.sh didn't solve the problem. I also set export JAVA_HOME=/usr/lib/jvm/java-7-openjdk-amd64 rather than just /usr/; JAVA_HOME should be the install directory of the JDK, since Ant will (I think) look in JAVA_HOME/bin and JAVA_HOME/lib.Casease
How can this be the accepted answer? It's not even an answer, per se.Santiago
I was just thinking the smae as @HeathHunnicutt, it seems everywhere I go to find answers to this question I'm met with "you must only have JRE installed" I know I have /usr/lib/jvm/java-11-openjdk-amd64/ so wtfOkie
W
5

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

Whippoorwill answered 16/6, 2014 at 21:51 Comment(0)
E
5
apt install defalut-jdk # this doesn't contain some file, like tools.jar...
apt install openjdk-8-jdk # this contains all files.
Eve answered 2/11, 2018 at 16:15 Comment(1)
Even if your answer is really helpful I believe that it can be improved by adding some explanation. Follow the link to know more how to write a good answerProgress
W
4

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.

Washburn answered 1/11, 2013 at 23:11 Comment(2)
Android has not yet been ported to Java 7 :/Choroiditis
thank you @Washburn this solved my problem. Don't know who down voted you but I upvoted your correct answer for Ubuntu 14.04 LTS .Porshaport
T
3

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::")

Tribalism answered 23/1, 2013 at 19:49 Comment(0)
A
2

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.

Assumption answered 16/2, 2014 at 18:37 Comment(0)
M
2

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
Miley answered 21/7, 2015 at 17:54 Comment(0)
K
2

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.)

Knudsen answered 25/12, 2015 at 8:44 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.