11

I am trying to execute `ant -version' and I get

C:\Users\owner>ant -version
Unable to locate tools.jar. Expected to find it in C:\Program Files\Java\jre7\lib\tools.jar
Apache Ant(TM) version 1.8.4 compiled on May 22 2012

I checked all of my environment variables and I cant find a reference to C:\Program Files\Java\jre7

I have the JDK and JRE installed at C:\Program Files (x86)\Java\jre7 and C:\Program Files (x86)\Java\jdk1.7.0_10

I also have stuff in C:\Program Files\Java\jre7 and C:\Program Files\Java\jdk1.7.0_10

Can anyone tell me why ant is looking in the wrong directory?

I have seen a bunch of other questions on stackoverflow but none of them solve my issue.

output of %path% is

C:\Users\owner>echo %path%
%CommonProgramFiles%\Microsoft Shared\Windows Live;C:\Windows\system32;C:\Window
s;C:\Windows\System32\Wbem;C:\Program Files (x86)\CyberLink\Power2Go;C:\Program
Files (x86)\ATI Technologies\ATI.ACE\Core-Static;c:\Program Files (x86)\Microsof
t SQL Server\90\Tools\binn\;C:\Program Files (x86)\QuickTime\QTSystem\;C:\Window
s\System32\WindowsPowerShell\v1.0\;C:\Program Files\Java\jdk1.6.0_24\bin;C:\Prog
ram Files\TortoiseSVN\bin;C:\Program Files (x86)\Java\jdk1.7.0_10;C:\Program Fil
es (x86)\Android\android-sdk\tools\apache-ant-1.8.4\bin;C:\Program Files (x86)\A
ndroid\android-sdk\platform-tools\;C:\Program Files (x86)\Android\android-sdk\to
ols\;C:\Program Files\Common Files\Microsoft Shared\Windows Live

C:\Users\owner>echo %JAVA_HOME%
%ProgramFiles(x86)%\Java\jdk1.7.0_10
DiverseAndRemote.com
  • 19,314
  • 10
  • 61
  • 70
  • What is the output of `echo %PATH%` in the command prompt where you are running ant? – Tanzeel Kazi Dec 20 '12 at 03:24
  • updated question with `echo %path%` – DiverseAndRemote.com Dec 20 '12 at 03:27
  • I was going to tell you to post the `JAVA_HOME` output too but someone has already posted an answer based on that. – Tanzeel Kazi Dec 20 '12 at 03:30
  • Okay seems like you updated your question. Since your environment variables are tallying out, can you also post your ant build/configuration file? – Tanzeel Kazi Dec 20 '12 at 03:32
  • Sorry this is my mistake. I was assuming you are running a build under ant. An ant project usually has a build.xml file associated with it. If you are looking to run ant under a specific JDK/JRE you can try the answer here http://stackoverflow.com/questions/7913467/setup-ant-to-use-jdk-different-from-one-specified-in-java-home . Also ensure that your ant environment variables are set as per the apache ant documentation under the section "Check Installation" at http://ant.apache.org/manual/install.html . – Tanzeel Kazi Dec 20 '12 at 03:39

2 Answers2

9

Ant does (unfortunately) rely on the JAVA_HOME system property. You will want to make sure that this property points to a valid JDK installation (and not a JRE).

Perception
  • 79,279
  • 19
  • 185
  • 195
6

I just figured out what it was

changing %JAVA_HOME% from %ProgramFiles(x86)%\Java\jdk1.7.0_10 to C:\Program Files (x86)\Java\jdk1.7.0_10 fixed it.

DiverseAndRemote.com
  • 19,314
  • 10
  • 61
  • 70