1
votes

I have installed Ant, and when I try the command ANT or ant -version I receive the error message:

'ant' is not recognized as an internal or external command, operable program or batch file.

I tried several solutions suggested online but none of them work. I am using Windows 7. Below is the output of the command echo %PATH%

C:\Users\t_boulc>echo %PATH%
C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\WINDOWS\System32\Wind owsPowerShell\v1.0\;C:\Program Files (x86)\RSA SecurID Token Common;C:\Program F iles (x86)\Perforce\;C:\Program Files\apache-ant-1.9.1\bin

C:\Users\t_boulc>ANT
'ANT' is not recognized as an internal or external command, operable program or batch file.

C:\Users\t_boulc>ant -version
'ant' is not recognized as an internal or external command, operable program or batch file.

C:\Users\t_boulc>echo %PATH%
C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\WINDOWS\System32\Wind owsPowerShell\v1.0\;C:\Program Files (x86)\RSA SecurID Token Common;C:\Program F iles (x86)\Perforce\;C:\Program Files\apache-ant-1.9.1\bin

Directory of C:\Program Files\apache-ant-1.9.1

06/28/2013  02:49 PM    <DIR>          .
06/28/2013  02:49 PM    <DIR>          ..
06/28/2013  03:23 PM    <DIR>          bin
06/28/2013  02:46 PM    <DIR>          etc
06/28/2013  02:25 PM            11,253 fetch.xml
06/28/2013  02:25 PM             4,445 get-m2.xml
06/28/2013  02:25 PM               126 INSTALL
06/28/2013  02:25 PM            86,299 KEYS
06/28/2013  03:23 PM    <DIR>          lib
06/28/2013  02:25 PM            15,289 LICENSE
06/28/2013  03:23 PM    <DIR>          manual
06/28/2013  02:25 PM               218 NOTICE
06/28/2013  02:25 PM             4,119 README
06/28/2013  02:25 PM           216,873 WHATSNEW
           8 File(s)        338,622 bytes
           6 Dir(s)  202,572,378,112 bytes free

C:\Program Files\apache-ant-1.9.1>
6
I don't see a JDK anywhere on your path. Did you install Java?Bill the Lizard
Visit this link which solves this issue. stackoverflow.com/questions/31173603/…Naveen Mosuru

6 Answers

3
votes

I recommend you create .cmd scripts to set environment variables instead of setting them in the Windows GUI, this way they are local to your command shell and wont interfere with other tools. Also, I would put the tools someplace other than the root directory, I use C:\opt (this is where I install other tools such as netbeans and jdks and such).

Make a devenv.cmd text file with the following content (replace the ant and jdk paths with whatever is correct for your machine). You can use a notepad to create a script but ensure that the 'All files' option is chosen and .cmd is written after the name.

set PATH=%BASEPATH%
set ANT_HOME=c:\opt\apache-ant-1.9-bin
set JAVA_HOME=c:\opt\jdk7
set PATH=%ANT_HOME%\bin;%JAVA_HOME%\bin;%PATH%

Whenever you open a new command shell (cmd.exe), run devenv.cmd (just go where you keep it , write devenv.cmd and hit enter) and it will make the changes for the current command shell only without affecting the rest of the system. After running devenv.cmd, you should be able to run ant and jdk tools (javac, etc) from command line.

You can check ANT_HOME' location with echo %ANT_HOME% command ..

0
votes

/bin/ant is actually a bash shell script, so you might need to call ant.bat - try entering the complete path directly at the prompt:

"C:\Program Files\Ant\apache-ant-1.9.1\bin\ant.bat"
Buildfile: build.xml does not exist!
Build failed
0
votes

Your path is somewhat strange. It escapes semi-colon --";" It is not needed on windows.

C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\WINDOWS\System32\Wind owsPowerShell\v1.0;C:\Program Files (x86)\RSA SecurID Token Common;C:\Program Files (x86)\Perforce;C:\Program Files\apache-ant-1.9.1\bin

0
votes

THIS is the answer: make a User Variable:

Name= PATH
Value= %JAVA_HOME%\bin;%ANT_HOME%\bin  --->NO SPACES and JAVA_HOME first

make 2 new system variables:

JAVA_HOME with value C:\...path-to-Jdk (usually program files/java/jdk)
ANT_HOME with value C:\path-to-apache-ant-1.x.x

This solves :

Ant/Javac is not recognized as an internal or external command, operable program or batch file

Unable to locate tools.jar. Expected to find it in C:\Program Files\Java\jre1.6.0_03\lib\tools.jar
Apache Ant version 1.7.0 compiled on December 13 2006 
0
votes

First create a user variable ANT_HOME and assign the installation directory to it, e.g.:

ANT_HOME="D:\apache-ant-1.9.6"

Using the command prompt set the PATH as:

C:>set %ANT_HOME%/bin C:>ant -version Apache Ant version 1.7.1 compiled on June 27 2008 C:>