0
votes

I am installing ant on a Windows XP machine, and am following the instructions at Apache's manual site. It said to set JAVA_HOME, so I checked, saw there was no environment variable named JAVA_HOME, made one, and set it to "C:\Program Files\Java\jdk1.6.0_19"

When I try to run ant debug, however, it tells me that JAVA_HOME is currently set to "C:\Program Files\Java\jre6"

I'm guessing JAVA_HOME isn't an environment variable. But if it isn't one, I'm at a loss as to where to start looking for it. Anybody know?

Edit: Oh yeah - it's bugging me for tools.jar as well, but I'm guessing that when I fix the JAVA_HOME issue, that will help the terminal find tools.jar as well. Or maybe I'm wrong. Thanks

2
Yes, once your JAVA_HOME is correct and points at a JDK, it will find tools.jar. - Joshua McKinnon
I found debugging this problem intolerable so simple put the tools.jar where Ant expected to find it. Sometime surrender is the best policy. - Tim Bender
You know what? I was considering the same thing earlier but I was afraid to try it on a work PC. Thanks for the suggestion. Works fine now. - StormShadow

2 Answers

5
votes

Following on Newtopian's suggestions, you can quickly confirm if that behavior is the problem by running in the terminal

C:\>set JAVA_HOME=C:\Program Files\Java\jdk1.6.0_19
C:\>ant debug

Also, I'm not sure if the text you entered into the JAVA_HOME environment variable is literally "C:\Program Files\Java\jdk1.6.0_19", i.e., with quotes, but if so, you should remove the quote marks as they'll throw off ant.bat.

Here's the relevant bit from ant.bat

:checkJava
set _JAVACMD=%JAVACMD%

if "%JAVA_HOME%" == "" goto noJavaHome
if not exist "%JAVA_HOME%\bin\java.exe" goto noJavaHome
if "%_JAVACMD%" == "" set _JAVACMD=%JAVA_HOME%\bin\java.exe
goto checkJikes

:noJavaHome
if "%_JAVACMD%" == "" set _JAVACMD=java.exe

... omitted ...

"%_JAVACMD%" %ANT_OPTS% -classpath "%ANT_HOME%\lib\ant-launcher.jar" "-Dant.home=%ANT_HOME%" org.apache.tools.ant.launch.Launcher %ANT_ARGS% %ANT_CMD_LINE_ARGS%

If that doesn't help, could you post your debug task?


Two options to make it permanent:

  1. Run this:

    C:\>REG delete HKCU\Environment /V JAVA_HOME
    C:\>REG delete HKLM\Environment /V JAVA_HOME
    C:\>REG add HKCU\Environment /V JAVA_HOME /d "C:\Program Files\Java\jdk1.6.0_19"

(basically, ensure you only have one JAVA_HOME set and it's correct; be sure to close and reopen the terminal after doing this)

  1. If all else fails, the crappy batch file solution:

    @echo off
    set JAVA_HOME=C:\Program Files\Java\jdk1.6.0_19
    ant %*

save as ant_wrapper.bat (or whatever) and you should be able to do ant_wrapper debug.

(Both of these solutions are untested)

3
votes

Make sure you check both user and system scope environment Variables. I am not certain what is the precedence of one over the other here but most likely you checked as only one and created it there and it is being overridden by the other.

Also when you create the environment variable make sure you open a new command shell for the changes to take effect. then try 'set' that will list all environment variables seen in the environment for the command prompt you just created.

If all is well there but Ant still does not see the correct one then check the batch files that start ANT if the javahome is not set there too. If it is make sure it uses the environment variable and does not try and set it again.

Hope this helps