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

19,650

I later discovered that tools.jar wasn't in the jdk directory. I ran the command yum install java-1.8.0-openjdk-develand lib/tools.jarbecame available in the java folder. When I ran the ant command after this, I did not get the same warning.

Share:
19,650

Related videos on Youtube

a_sid
Author by

a_sid

Updated on September 18, 2022

Comments

  • a_sid
    a_sid over 1 year

    I created a script in /etc/profile.d and named it jdk_home.sh. The contents of jdk_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.shon the command line. After that, I typed echo $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 put build.xml in that folder. My build.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
    Bratchley about 7 years
    For 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'
    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
    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
    Admin almost 2 years
    For ubuntu users check if you install openjdk or openjdk-headless , if you install headless tools.jar is not installed