views:

296

answers:

2

Hey all, 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

+3  A: 

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

Newtopian
Yeah, ran set and sure enough it gave me the wrong value for JAVA_HOME. Unfortunately, I'm not an admin on this machine, so I don't know. I guess I will have to set it via command line every time or something.
StormShadow
+4  A: 

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)

ig0774
That did the trick!I'm not sure how to make the setting "stick" though. I have to reset it every time I open a new terminal window.Oh, and a quick note to anybody else doing this: if you get a BUILD FAILED after everything else seemed fine, check and make sure that your emulator isn't asleep/dimmed when you run ant install. That took me ten minutes to figure out. :-)
StormShadow
@stormshadow see my edit above
ig0774
oh, if you're running as a non-admin user you may have to skip the REG delete HKLM line, and the batch file may be the only solution.
ig0774
Thanks - I couldn't delete any variables from the command line and I have no experience with batch files so I went with Tim's solution above and just copied tools.jar into where the PC is looking. Works fine now. Thanks anyway
StormShadow
Great. I'm glad you managed to get things working!
ig0774