unable to locate tools.jar. Proper solution? - ant

I have find so many question related to this in SO.
When i type ant -version in the command prompt, the following is printed:
Unable to locate tools.jar. Expected to find it in C:\Program Files\Java\jre1.8\lib tools.jar
Apache Ant version 1.9.4 compiled on April 29 2014
Even though it is saying "Unable to locate tools.jar......" it is also printing the version number.
All the other solutions didn't work EXCEPT copying the tools.jar from:
C:\Program Files\Java\jdk1.8.0_31\lib and paste it in
C:\Program Files\Java\jre1.8.0_31\lib
After this, when i typed ant -version, only Apache Ant version 1.9.4 compiled on April 29 2014 is diplayed.
Is this solution recommeded?
FYI:
Before installing jdk 1.8, I had jdk 1.7 and jre 1.8 already installed separately. Now I have all the three inside the same folder C:\Program Files\Java.
In Environment variable->System variables , I have defined:
JAVA_HOME: C:\Program Files\Java\jdk1.8.0_31;
ANT_HOME: ant path
And in the PATH included C:\Program Files\Java\jdk1.8.0_31\bin;
and ant bin path also.

By setting the following Environmental variables as below, my issue was resolved:
In Environment variable->User variables , I have defined:
ANT_HOME: C:\Program Files\apache-ant-1.9.4
In Environment variable->System variables , I have defined:
JAVA_HOME: C:\Program Files\Java\jdk1.8.0_31;
And in the Path added the following things:
C:\Program Files\Java\jdk1.8.0_31\lib;C:\Program Files\Java\jdk1.8.0_31\bin;
In my case I was trying some ant script with adb and svn and I don't know whether they were related or not. Because my ADT bundle was in Desktop, so I had to put it inside C drive.
In order to work properly I had to setup my environmental variables with following extra paths:
In Environment variable->User variables , I have defined:
SVN_PATH : C:\Program Files\TortoiseSVN
ANDROID_HOME : C:\Program Files\adt-bundle-windows\sdk
Inside Environment variable->System variables :
in the Path added the following paths:
C:\ProgramFiles\TortoiseSVN\bin;
C:\Program Files\adt-bundle-windows\sdk\platform-tools;
C:\Program Files\adt-bundle-windows\sdk\tools;
%ANDRIOD_HOME%\platform-tools;
%ANDRIOD_HOME%\tools;
%SVN_PATH%\bin;
C:\Program Files\SlikSvn\bin;

Are you sure that the PATH variable contains only one Java path?
This may be linked to java defined twice on your PATH (with the secon being JRE location).
I had exaclty the same problem in eclipse (which should look for JDK rather than JRE), and the solution was to just manually configure java location in eclipse.

It's a very easy proccess
Copy tools.jar from JDK lib folder & paste it in JRE lib folder .....Just Make sure JDK & JRE installed on your C drive and point their paths in Environment settings.
Once it is done. Open Command Prompt
Type ant -v
If You get below messages then ANT is installed successfully
c:>ant -v
Apache Ant(TM) version 1.10.1 compiled on February 2 2017
I hope it will help.
Thanks,
Priya Gupta

Related

Jenkins requires Java versions [8, 11] but you are running with Java 16 from C:\Program Files\Java\jdk-16.0.1

Trying to install Jenkins but it is showing me this error.
Jenkins requires Java versions [8, 11] but you are running
with Java 16 from C:\Program Files\Java\jdk-16.0.1
Please help!
Download java 11 from below link & install in your system.
https://www.oracle.com/in/java/technologies/javase-jdk11-downloads.html
After installing you can find the folder in C:\Program Files\Java\
since I have already installed java 16, I don't want to change the default to 11.
Run Jenkins as mentioned below:
open command prompt using run as administrator mode
switch to >>>
C:\Windows\system32> >>
cd C:\Program Files\Jenkins
Execute this command
C:\Program Files\Jenkins>..\Java\jdk-11.0.12\bin\java -jar jenkins.war --httpPort=8080
Jenkin starting after executing above command
Go to HTTP://localhost:8080
You can find admin password from C:\Users\myuser\\.jenkins\secrets\initialAdminPassword
Go to HTTP://localhost:8080
In my case, I was not able to fix it with the above solutions. So, what worked for me is, in environment variables, you can update the path of JAVA_HOME as C:\Program Files\Java\jdk1.8.0_321 or the specific path in which you have your java installed. The advantage here is you need not delete the other versions of java. Also remember you need to delete C:\Program Files\Common Files\Oracle\Java\javapath
C:\Program Files (x86)\Common Files\Oracle\Java\javapath from the existing system variables so that it will consider version 8 as default.
Also need to update the java version pointing in the jenkins to jdk1.8.0_321 in the C:\Program Files\Jenkins\jenkins.xml file
<executable>C:\Program Files\Java\jdk1.8.0_321\bin\java.exe</executable>
Create 2 batch files using solution provided by
Bala Subramanium
so u can start Jenkins with one/two click/s
First Bat File is Jenkins_Initiate.bat ------>>>>> (use to start Jenkins)
cd C:\Program Files\Jenkins
..\Java\jdk-11.0.13\bin\java -jar jenkins.war --httpPort=8080
make sure to have 2 spaces between java & -jar
Second Bat File is Jenkins_Launch.bat ------>>>>> (use to lauch Jenkins on chrome)
start chrome http://localhost:8080
You can use the option —enable-future-java.
You can run jenkins.war on command prompt with the above option. Or you can edit xml file jenkins within your installed Jenkins package to add this option. The following blog discusses this solution. https://medium.com/#rakhi.mundhada1/how-to-run-jenkins-with-java-17-on-a-windows-machine-2a1b1c50960a
Same can be applied to Java 16.

Installation issue with Ant 1.9.4

I have got a problem with the Ant installation version 1.9.4...
I've downloaded the Ant apache-ant-1.9.4-src.zip from apache official website and extracted the zip to C:\Development\apache-ant-1.9.4
I've added the below in environment variable
ANT_HOME : C:\Development\apache-ant-1.9.4
JAVA_HOME : C:\Program Files\Java\jdk1.7.0_07
PATH : %PATH%;%JAVA_HOME%\bin;%ANT_HOME%\bin;
When I ran the "ant" cmd from command prompt, I got the below issue
C:>ant
ANT_HOME is set incorrectly or ant could not be located. Please set ANT_HOME.
C:\>echo %ANT_HOME%
C:\Development\apache-ant-1.9.4
Moreover, Bin folder is not found in downloaded .zip package.
Please anyone let me know, what i did wrong here?
You have downloaded the source of Apache Ant. You need to download the binary package. It should be something like apache-ant-1.9.4.zip.
The alternative is of course to compile the binary on your machine.

build.xml expects tools.jar at a different location

While using Ant to build my application, the build is successful but at the beginning it says
Unable to locate tools.jar. Expected to find it in
D:\Java\jre6\lib\tools.jar
However my tools.jar is at the location D:\Java\jdk6u30\lib
I understand that tools.jar contains classes needed by jdk and should only be present at jdk lib and nowhere else. I hope I am correct on this.
My question is that why does build.xml expects it at a different location? I have my JAVA_HOME
set to
D:\Java\jdk6u30
.
So by default eclipse will take the jre as installed JRE's when you add the server. Change the installed JRE's to jdk.
You can locate it from Window->Preferences->Java->installed JRE's

Ant + Vista 64 : "Unable to locate tools.jar" (jre/jdk conflict?)

I'm trying to use ant in a vista 64 environment to build some docbook/xml files.
However, I can't resolve this error message. Anybody have suggestions?
C:\Users\Robert Admin>ant
Unable to locate tools.jar. Expected to find it in C:\Program Files\Java\jre6\li
b\tools.jar
Buildfile: build.xml does not exist!
Build failed
Googling around, I see that this tools.jar message is the result of ant not being able to find the jdk. In fact, C:\Program Files\Java\jre6\li
b\tools.jar is a JRE installed with another program (I'm guessing). Tools.jar is located here: C:\Program Files\Java\jdk1.6.0_22\lib
I can't seem to tell Ant to look in the JDK path, only the JRE path which was already there. (Judging from the Ant documentation, it seems that JRE is insufficient).
C:\Users\Robert Admin>echo %JAVA_HOME%
C:\Program Files\Java\jdk1.6.0_22\bin
C:\Users\Robert Admin>ant
Unable to locate tools.jar. Expected to find it in C:\Program Files\Java\jre6\li
b\tools.jar
Buildfile: build.xml does not exist!
Build failed
C:\Users\Robert Admin>echo %ANT_HOME%
I:\My Documents\1latest\ant
C:\Users\Robert Admin>where java
C:\Windows\System32\java.exe
C:\Program Files (x86)\Java\jre6\bin\java.exe
C:\Program Files\Java\jdk1.6.0_22\bin\java.exe
C:\Users\Robert Admin>java -version
java version "1.6.0_22"
Java(TM) SE Runtime Environment (build 1.6.0_22-b04)
Java HotSpot(TM) 64-Bit Server VM (build 17.1-b03, mixed mode)
Update #1. I tried uninstalling the 64 bit jdk and installing the 32 bit jdk. Result:
C:\Users\Robert Admin>java -version
java version "1.6.0_22"
Java(TM) SE Runtime Environment (build 1.6.0_22-b04)
Java HotSpot(TM) 64-Bit Server VM (build 17.1-b03, mixed mode)
C:\Users\Robert Admin>ant
Unable to locate tools.jar. Expected to find it in C:\Program Files\Java\jre6\li
b\tools.jar
Buildfile: build.xml does not exist!
Build failed
C:\Users\Robert Admin>echo %JAVA_HOME%
C:\Program Files (x86)\Java\jdk1.6.0_22\bin
I had the same problem because my JAVA_HOME path was set incorrectly (just like the OP's). It was set to the bin of the jdk.
So it was set to:
C:\Program Files (x86)\Java\jdk1.6.0_25\bin
When it should have been set to:
C:\Program Files (x86)\Java\jdk1.6.0_25
Updating this environmental variable fixed it for me.
I had this problem on a 64-bit Windows 7 machine and Ant 1.8.2. The solution was to use the admin tools mentioned by #bigfix to set the environment variables. Follow the Ant installation instructions for Windows. But do not set the path as %ANT_HOME%\bin. Instead, use an explicit path such as C:\jdk-1.5.0.05\bin.
My first test failed because my command window was already open and using the old env vars. Close it and open a new one. Then try the test. It worked for me.
I fixed this by creating JAVA_HOME in computer-> properties-> env variables
Manual setup in command line did not work
-b
I solved the problem by creating system variable JAVA_HOME to C:\Program Files\Java\jdk1.6.0_25. Don't put the semi colon after it. First of all I put the semi colon and there was an error. I removed the semi colon and it worked.
All you need is to set JAVA_HOME path in your environment. In Windows 7 go to "System Properties -> Advanced -> Environment Variables" and add JAVA_HOME. The value in my case was:
C:\Program Files\Java\jdk1.7.0_07
This resolved the issue for me. This variable points Ant to the correct Java location.
I know this thread is some what old..but i faced it just now too..what i did was copy that tools.jar into jre/lib folder and worked fine.
I'm in Windows 7 , JDK 1.7 environment and trying to install ant 1.8.2
Thanks
you may be using the java in the C:\Windows\system32 directory rather then the installed JDK. I set a JAVA_HOME environmental variable and put %JAVA_HOME%\bin at the start of my path and the problems when away.
why don't you try the 32 bit version. there could be a problem between the two versions you have installed being 32 and 64. try the 32 bit version so ur not seeing any 64 bit versions.
it should fix ur problem.
I had this issue with Environment as :
Windows 7
Java version jdk1.6.0_33
apache-ant-1.6.5
I Was getting ant build message as "Unable to locate tools.jar. Expected to find it in E:\Java\jre6\lib\tools.jar", where my JDK was installed at E:\Java\jdk1.6.0_33\ and JRE at E:\Java\jre6\
Cause:
My issue was that I have ANT_HOME was set twice in the PATH system Environment variable at two different places (means some other variables in between).
Solution:
I removed the ANT_HOME variable that pointed to the wrong location and everything worked fine with me.
I once faced the same problem of ant setup. The promotion is just the same as
Unable to locate tools.jar`. Expected to find it in C:\Program Files\Java\jre6\li b\tools.jar
Buildfile: build.xml does not exist! Build failed.
I deleted all jre path in %PATH% environment and add jdk bin path. Finally I type %ANT_PATH%/bin instead of %ANT_PATH%\bin. It works.
May help.
I got the same issue.
Successfully resolved.
Check your systeminformation that jenkins see : your_jenkins_url/systemInfo
Look for "JAVA_HOME" variable in the "Environment Variables" section. In my case I was not able to found it.
So if you do not see this variable it means that your variable was not set for the user that jenkins run under. You need to put "JAVA_HOME" in to the "system variables" section of environment variables, not "user variables".
restart jenkins after this and your problem must be fixed.
I was getting a "C:\Program" is not recognized as an internal or external command, operable program or batch file error, when running %ANT_HOME%\bin\ant.bat
I found that I needed to wrap the command in double-quotes in order to get the proper escaping to happen on the path string.
FIX:
"%ANT_HOME%\bin\ant.bat" --NOT-- %ANT_HOME%\bin\ant.bat
Hope that helps!
Thanks, this also works on Windows 8, x64, using Java x64.
I didn't want to add all that junk to my system settings so I created a batch file that I'd run just before I wanted to use the Android SDK. Here it is
set ANDROID_SDK_PT=C:\Program Files\eclipse\sdk\platform-tools
set ANDROID_SDK_TOOLS=C:\Program Files\eclipse\sdk\tools
set JAVA_HOME=C:\Program Files\Java\jdk1.7.0_25
set ANT_HOME=C:\apache-ant
set PATH=%PATH%;%ANDROID_SDK_PT%;%ANDROID_SDK_TOOLS%;%JAVA_HOME%;%ANT_HOME%\bin
I am going to add one other issue that I had with this.
BTW, the answer here worked for me too. I had to point my java directory to the specific SDK version. Thank you very much.
But I'm going to add that I had to install the SDK as an administrator, or it didn't extract tools.jar. I found this answer elsewhere, and I hope it helps someone to repeat it here.

Why does ANT tell me that JAVA_HOME is wrong when it is not?

I get the error:
C:\dev\ws\springapp\build.xml:81: Unable to find a javac compiler;
com.sun.tools.javac.Main is not on the classpath.
Perhaps JAVA_HOME does not point to the JDK.
It is currently set to "C:\Program Files\Java\jre6"
But I have clearly set my JAVA_HOME to be C:\Program Files\Java\jdk1.6.0_14
Where is ANT getting this value?
In Eclipse click Run → External Tools → External Tools Configurations.
Click the JRE tab.
Click the Installed JREs... button.
Click the Add button.
(Select Standard VM, where applicable.)
Click the Directory button.
Browse to your JDK version (not JRE) of your installed Java
(e.g. C:\Program Files\Java\jdk1.7.0_04).
Click Finish and OK.
Select the JDK at Separate JRE and click Close.
Re-run your Ant script — have fun!
This worked in a particular scenario I encountered.
When you say you have "clearly set" JAVA_HOME to "C:\Program Files\Java\jdk1.6.0_14" - is that what you see when you run "set" from the command line? I believe Ant will guess at a value for JAVA_HOME if one isn't set at all... is it possible that you've set JAVAHOME instead of JAVA_HOME?
If it's nothing like that, I suggest you edit the ant.bat batch file (and whatever it calls - I can't remember whether it's convoluted or not offhand) to print out JAVA_HOME at the start and at various other interesting places.
I encountered the same problem when I try to run Ant build using the following command:
java -cp ant.jar:ant-launcher.jar org.apache.tools.ant.Main
The output of the command is:
BUILD FAILED
XXX/build.xml:8: Unable to find a javac compiler;
com.sun.tools.javac.Main is not on the classpath.
Perhaps JAVA_HOME does not point to the JDK.
It is currently set to "/usr/lib/jvm/java-6-openjdk/jre"
It seems the java executable is picking "/usr/lib/jvm/java-6-openjdk/jre" as JAVA_HOME, as opposed to "/usr/lib/jvm/java-6-openjdk" where JDK is installed.
I resolved this issue by setting fork="yes" in my <javac> task.
Take a look at: http://ant.apache.org/manual/Tasks/javac.html
It's also possible that you have included /bin in your JAVA_HOME setting, and Ant is adding /bin to it - thereby not finding any exe's. It's happened to me :}
Make sure you do not use the trailing semicolon: This will not work:
set JAVA_HOME=C:\Program Files (x86)\Java\jdk1.6.0_29;
This will:
set JAVA_HOME=C:\Program Files (x86)\Java\jdk1.6.0_29
I have met the similiar issue. I would link to run Ant task fron Maven build and I got the issue. I have fixed it as bellow steps:
Make sure JAVA_HOME is set right. You can check it on Windowns in command line as:
C:>echo %JAVA_HOME%
Result would look like: C:\Progra~1\Java\jdk1.6.0_30\
Copy file tools.jar from %JAVA_HOME%\lib to lib directory of Maven.
And it worked for me.
To solve this problem add tools.jar file in window->preferences->ant-> runtime .
In eclipse set the installed JRE setting to the JDK - in the project (project properties -> Java Build Path-> Libraries), or global default in preferences (Java->Installed JREs). The eclispe setting is stronger than the system variable.
I hope you are aware about System and User environmental variables. The user ones are preferred over system. If you have set your JAVA_HOME in system variables and if there is an entry for the same in user variables, then you will get the latter one only.
Right click on My computer, Go to properties, Select Advanced tab and click on Environmental variables to see the list of user and system environment variables.
The semicolon was throwing me off: I had JAVA_HOME set to "C:\jdk1.6.0_26;" instead of "C:\jdk1.6.0_26". I removed the trailing semicolon after following Jon Skeet's suggestion to examine the ant.bat file. This is part of that file:
if "%JAVA_HOME%" == "" goto noJavaHome
if not exist "%JAVA_HOME%\bin\java.exe" goto noJavaHome
So the semi-colon wasn't being trimmed off the end, causing this to fail to find the file, therefore defaulting to "C:\Java\jre6" or something like that.
The confusing part is that the HowtoBuild page states to use the semi-colon, but that seems to break it.
I was facing the same problem, making the executable property in the javac tag to be set to the location of javac.exe resolved the problem for me.
This resolved the problem
<javac srcdir="${srcDir}" destdir="${buildDir}" fork="true" executable="C:\Program Files\Java\jdk1.7.0_03\bin\javac"/>
Actually found this answer on superuser.com, but I had to copy tools.jar from my JDK\lib directory to the JRE\lib directory.
Makes ZERO sense...only thing I can think of is Sun introduced this bug in the latest Java runtime (Java 7 Update 11) or a bug in Ant in how it reads the current JDK location (the JRE is more updated than the JDK obviously which is also stupid of Sun...they should release the JDK each time they update the JRE).
My JAVA_HOME was set correctly. I confirmed by doing "set JAVA_HOME". It pointed to my JDK directory and was spelled correctly. However, Ant was claiming it couldn't find javac, but thought JAVA_HOME was in my JRE directory.
My system worked fine before the latest Sun JRE7 updates (10 and 11). Ant is version 1.8.4
If you have JAVA_HOME set but there's a typo in it, you will also see the bogus reference to a jre6 path.
When everything else is correct try the following
Goto Window -> Preferences -> Ant -> Runtime -> ClassPath
Expand Global Entries and check jdk tools available here.
Add the required tools.jar from a specific version of java such as "C:\Program Files\Java\jdk1.6.0_45\lib\tools.jar"
Now build and check the results.
Note: Add tools.jar for the java compiler that you want to use and give preference to it by moving it up in the list of tools.jar when multiple tools.jar (java compilers) are present.
Just set the JDK path from the below steps:
Go to 'Run' ->External Tools -> External Tools Configuration
-> Select 'JRE'
Then from the DropDown list select the available JDK . ex. jdk1.8.0_25
I had the same problem. My JDK package pointed by JAVA_HOME didn't have any tools.jar
Be sure that your JDK instal.lation has tools.jar
(clearly the message error is confusing)
Set JAVA_HOME in the environment variables as D:\Program Files\IBM\SDP\jdk
Do not give any quotes or semicolon. It's works for me.Please try the solution.
Actually in ant.bat it checks for appropriate JAVA_HOME in case if ant.bat not able to find it then it's JAVA_HOME points the default JRE.
I was also facing the same problem. I am using Windows 7 and I had two versions of java installed. First I have installed latest version java 7 and then version 5.
Contents of my java installation directory:
C:\Program Files\Java>
jdk1.5.0_14
jdk1.7.0_17
jre1.5.0_14
jre7
and my JAVA_HOME was set to the correct value, which was:
C:\>set ja
JAVA_HOME=C:\Program Files\Java\jdk1.5.0_14
But still I was getting the same problem:
XXXXXXX\build.xml:478: The following error occurred while
executing this line:
XXXXXXX\build.xml:477: Unable to find a javac compiler;
com.sun.tools.javac.Main is not on the classpath.
Perhaps JAVA_HOME does not point to the JDK.
It is currently set to "C:\Program Files\Java\jre7"
After trying out all the suggestion in this thread I realized my mistake. I was trying to set the environment variable in "User variables" instead of "System Variables" section. After setting it in "System Variables" it worked fine. I am facing another problem though.
The default version of java it points to is still 7.
C:\>java -version
java version "1.7.0_17"
Java(TM) SE Runtime Environment (build 1.7.0_17-b02)
Java HotSpot(TM) Client VM (build 23.7-b01, mixed mode, sharing)
I am not sure how to make it point to version 5.
I faced this problem when building my project with Jenkins. First, it could not find ant.bat, which was fixed by adding the path to ant.bat to the system environment variable path. Then ant could not find the jdk directory. This was fixed by right-clicking on my computer > properties > advanced > environment variables and creating a new environment variable called JAVA_HOME and assigning it a value of C:\Program Files\Java\jdk1.7.0_21. Don't create this environment variable in User Variables. Create it under System Variables only.
In both cases, I had to restart the system.
It is common to get this issue. I cannot set any specific Java home in my system as I have 2 different version of Java (Java 6 and Java 7) for different environment.
To resolve the issue, I included the JDK path in the run configuration when opening the build.xml file.
This way, 2 different build files use 2 different Java version for build.
I think there might be a better solution to this problem but at least the above approach avoid setting the JAVA_HOME variable.
FYI, I am using Windows 7 and had to restart Windows in order for the new JAVA_HOME setting to take effect.
had the same problem;
c:\jb\src\build.xml:191: Unable to find a javac compiler;
com.sun.tools.javac.Main is not on the classpath.
Perhaps JAVA_HOME does not point to the JDK.
It is currently set to "C:\Program Files\Java\jre7"
Total time: 0 seconds
c:\jb\src>echo %JAVA_HOME%
c:\Program Files\Java\jdk1.7.0_13
solution:
path = c:\ant\bin\;%PATH%
path = c:\Program Files\Java\jdk1.7.0_17\bin;%PATH%
set "JAVA_HOME=c:\Program Files\Java\jdk1.7.0_13"
I guess the jdk path instruction alone would do it but I'm to lazy to figure it out above solution is bullet proof. :-)
Also using Windows7
Quick work around for the same is
Copy C:\Program Files\Java\jdk1.6.0_14\lib\tools.jar to C:\Program Files\Java\jre6\lib\
This exception is coming because JAVA_HOME is being set as C:\Program Files\Java\jre6 and Ant is not able to find tools.jar in it.
If need to run ant in eclipse with inbuilt eclipse jdk add the below line in build.xml
<property name="build.compiler" value="org.eclipse.jdt.core.JDTCompilerAdapter"/>

Resources