简体   繁体   English

安装蚂蚁; 明显误会JAVA_HOME

[英]Installing ant; clearly misunderstanding JAVA_HOME

I am installing ant on a Windows XP machine, and am following the instructions at Apache's manual site . 我正在Windows XP计算机上安装ant,并且正在按照Apache手册站点上的说明进行操作 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" 它说要设置JAVA_HOME,所以我检查了一下,发现没有名为JAVA_HOME的环境变量,将其设置为1,然后将其设置为“ 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" 但是,当我尝试运行ant debug时,它告诉我JAVA_HOME当前设置为“ C:\\ Program Files \\ Java \\ jre6”

I'm guessing JAVA_HOME isn't an environment variable. 我猜JAVA_HOME不是环境变量。 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. 编辑:哦,是的-它也在困扰我的tools.jar,但是我猜想当我修复JAVA_HOME问题时,这也将帮助终端也找到tools.jar。 Or maybe I'm wrong. 也许我错了。 Thanks 谢谢

Following on Newtopian's suggestions, you can quickly confirm if that behavior is the problem by running in the terminal 根据Newtopian的建议,您可以通过在终端中运行来快速确认该行为是否是问题所在

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", ie, with quotes, but if so, you should remove the quote marks as they'll throw off ant.bat. 另外,我不确定您输入到JAVA_HOME环境变量中的文本是否为“ C:\\ Program Files \\ Java \\ jdk1.6.0_19”,即带引号,但如果这样,则应将引号删除为他们会抛弃ant.bat。

Here's the relevant bit from ant.bat 这是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) (基本上,请确保只设置了一个JAVA_HOME且正确;请确保在执行此操作后关闭并重新打开终端)

  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 . 另存为ant_wrapper.bat (或其他任何文件),您应该能够进行ant_wrapper debug

(Both of these solutions are untested) (这两种解决方案均未经测试)

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. 如果一切都很好,但是Ant仍然看不到正确的文件,那么如果javahome那里也没有设置,请检查启动ANT的批处理文件。 If it is make sure it uses the environment variable and does not try and set it again. 如果确定,请确保它使用环境变量,并且不要尝试再次设置它。

Hope this helps 希望这可以帮助

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM