Error installing Ant: ANT_HOME is set incorrectly

2019-01-03 06:56发布

I read all the possible solutions but the none worked. I downloaded the ant and put it in C:\ant (so I have C:\ant\bin)

On Windows 7 under System variables I have variable called ANT_HOME with value

C:\ant

and variable called PATH with value

%ANT_HOME%\bin

And when I try in cmd (Command Prompt)

ant -version

I get

ANT_HOME is set incorrectly or ant could not be located. Please set ANT_HOME.

Also, if I try

echo %ANT_HOME%

I get

C:\ant

I tried PATH = %PATH%;%ANT_HOME%\bin but the same situation. Anyone?

EDIT:

Variables are (name - value):

ANT_HOME - C:\ant
CLASSPATH - .;C:\Program Files\Java\jre6\lib\ext\QTJava.zip
ComSpec - %SystemRoot%\system32\cmd.exe
FP_NO_HOST_CHECK - NO
JAVA_HOME - C:\Program Files\Java\jdk1.6.0_23
NUMBER_OF_PROCESSORS - 2
OS - Windows_NT
PATH - %ANT_HOME%\bin;%JAVA_HOME%\bin
PATHEXT - .COM;.EXE;.BAT;.CMD;.VBS;.VBE;.JS;.JSE;.WSF;.WSH;.MSC
PROCESSOR_ARCHITECTURE - x86
PROCESSOR_IDENTIFIER - x86 Family 6 Model 15 Stepping 6, GenuineIntel
PROCESSOR_LEVEL - 6
PROCESSOR_REVISION - 0f06
PSModulePath - %SystemRoot%\system32\WindowsPowerShell\v1.0\Modules\
QTJAVA - C:\Program Files\Java\jre6\lib\ext\QTJava.zip
TEMP - %SystemRoot%\TEMP
TMP - %SystemRoot%\TEMP
USERNAME - SYSTEM
windir - %SystemRoot%
XNAGSShared - C:\Program Files\Common Files\Microsoft Shared\XNA\
XNAGSv4 - C:\Program Files\Microsoft XNA\XNA Game Studio\v4.0\

标签: java ant
30条回答
我命由我不由天
2楼-- · 2019-01-03 07:22

Adding manually from Windows sometimes does not work...

To solve this, open command prompt and type these commands;

C:\>set ANT_HOME=C:\apache-ant-1.9.2
C:\>set JAVA_HOME=C:\jdk1.7.0_25
C:\>set PATH=%ANT_HOME%\bin;%JAVA_HOME%\bin

... then test:

C:\>ant -version 
Apache Ant(TM) version 1.9.2 compiled on JULY 8 2013
查看更多
不美不萌又怎样
3楼-- · 2019-01-03 07:22

The trick is in avoiding spaces altogether!

Make sure that you don't add any unneeded spaces when adding to the PATH

PATH = %JAVA_HOME%\bin;%ANT_HOME%\bin

查看更多
Root(大扎)
4楼-- · 2019-01-03 07:23

I had the same issue and I was able to fix it by defining the %JAVA_HOME%\bin variable before defining the %ANT_HOME%\bin in my Path.

CORRECT: Path %JAVA_HOME%\bin;%ANT_HOME%\bin;........

WRONG: Path %ANT_HOME%\bin;%JAVA_HOME%\bin;.......

查看更多
贪生不怕死
5楼-- · 2019-01-03 07:24

Looks like there is an issue with apache-ant-1.8.3\bin\ant.bat.

Just comment the following lines in ant.bat and set the ANT_HOME environment variable and it should work.

if "%ANT_HOME%"=="" goto setDefaultAntHome

:stripAntHome
if not _%ANT_HOME:~-1%==_\ goto checkClasspath
set ANT_HOME=%ANT_HOME:~0,-1%
goto stripAntHome

:setDefaultAntHome
rem %~dp0 is expanded pathname of the current script under NT
set ANT_HOME=%~dp0..
查看更多
女痞
6楼-- · 2019-01-03 07:24

In my case it was a silly mistake, when you download the file I did not realize was that the directory, apache-ant-1.9.3-bin and copy directly to Program Files/apache-ant-1.9.3-bin. This gave me the error, I solved it by copying the apache-ant-1.9.3 folder is inside apache-ant-1.9.3-bin to Program Files/apache-ant-1.9.3 and perform the usual steps.

查看更多
▲ chillily
7楼-- · 2019-01-03 07:25

I set up the environment variables for Java and Ant correctly but it didnt work till I restarted System. Set Environment variables ANT_HOME, JAVA_HOME and restart system.

查看更多
登录 后发表回答