Why do I see "Unable to locate tools.jar. Expected to find it in ...." when I run ant (on RHEL 6.6) even though the path is set
I later discovered that tools.jar
wasn't in the jdk
directory. I ran the command yum install java-1.8.0-openjdk-devel
and lib/tools.jar
became available in the java folder.
When I ran the ant
command after this, I did not get the same warning.
Related videos on Youtube
a_sid
Updated on September 18, 2022Comments
-
a_sid over 1 year
I created a script in
/etc/profile.d
and named itjdk_home.sh
. The contents ofjdk_home.sh
are as follows :#!/bin/sh export JAVA_HOME=$(readlink -f /usr/bin/javac | sed "s:/bin/javac::") export PATH=$JAVA_HOME/bin:$PATH
(I followed an answer of this question on Stack Overflow to set up $JAVA_HOME).
I then typed
source /etc/profile.d/jdk_home.sh
on the command line. After that, I typedecho $JAVA_HOME
and it gave me the following output:/usr/lib/jvm/java-1.7.0-openjdk-1.7.0.131.x86_64
After I typed
echo $PATH
I got this output:/usr/lib/jvm/java-1.7.0-openjdk-1.7.0.131.x86_64/bin:/usr/lib/jvm/java-1.7.0-openjdk-1.7.0.131.x86_64/bin:/bin:/bin:/bin:/bin:/bin:/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.121-0.b13.el6_8.x86_64/bin:/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.121/bin:/bin:/usr/lib64/qt-3.3/bin:/usr/local/sbin:/usr/sbin:/sbin:/usr/local/bin:/usr/bin:/bin:/root/bin:/bin:/usr/apache/apache-ant-1.9.9/bin:/bin:/bin:/bin:/bin:/bin:/bin
I then opened another terminal in a project folder I named
dal
. I putbuild.xml
in that folder. Mybuild.xml
has the following contents:<project name="Hello World Project" default="info"> <target name="info"> <echo>Hello World - Welcome to Apache Ant!</echo> </target> </project>
I typed ant there on the command line:
[root@gksrv dal]# ant
This produced the following output:
Unable to locate tools.jar. Expected to find it in /usr/lib/jvm/java-1.8.0-openjdk-1.8.0.121-0.b13.el6_8.x86_64/lib/tools.jar Buildfile: /root/Desktop/dal/build.xml info: [echo] Hello World - Welcome to Apache Ant! BUILD SUCCESSFUL Total time: 0 seconds
Why am I seeing the
tools.jar
warning? Doesn't the path contain the required information? -
Bratchley about 7 yearsFor future reference on yum-based systems whenever you run into a "I need to know what to install to get this file" problem you can use
yum whatprovides <path-to-file>
for instance, in this case:yum whatprovides */tools.jar
Which lists all the packages that provide that file. That's usually a good one to start with. -
G-Man Says 'Reinstate Monica' about 7 years@Bratchley: I believe the OP’s problem was that he thought that he had the file, but the system just wasn’t looking in the right place. However, a more pertinent comment might be, “For future reference, whenever you get an
Unable to locate «file»
message, you should verify that you have the file, and determine where it is.” -
Bratchley about 7 years@G-Man I don't think the OP implies they thought anything other than it should be in
$PATH
somewhere. In that case just trying to install a JRE-appropriate package that contains the file and retrying the operation is a valid troubleshooting MO. -
Admin almost 2 yearsFor ubuntu users check if you install openjdk or openjdk-headless , if you install headless tools.jar is not installed