40

I have the same issue as this user: ant - not recognized as an internal

however unfortunately none of the solutions have worked for me in that post or any other. I've also looked at other commands not recognized and specifically adding a path variable. The procedure I am using is as follows:

Extract to a desired installation directory, e.g. C:\apache-ant
Create an ANT_HOME environment variable`

Open System Properties -> Advanced -> Environment Variables
Create a new system variable
    Variable name: ANT_HOME
    Variable value: C:\apache-ant 

Add %ANT_HOME%\bin directory to the PATH system variable

Open System Properties -> Advanced -> Environment Variables
Under system variables, select PATH and append ;%ANT_HOME%\bin
    e.g. %SystemRoot%\system32;%SystemRoot%;%JAVA_HOME%\bin;%ANT_HOME%\bin

Verify that ANT is installed.

Open a new command window and type:
C:\>ant -v`

In my case the Variable value is C:\apache-ant\apache-ant-1.8.2.

My exact path variable is %SystemRoot%\system32;%SystemRoot%;%JAVA_HOME%\bin;%SystemRoot%\System32\Wbem;%SYSTEMROOT%\System32\WindowsPowerShell\v1.0\;%JAVA_HOME%\bin;%ANT_HOME%\bin which doesn't have any spaces between semicolons.

However testing the ant installation does not work, the picture below is what I'm experiencing:

enter image description here

I have tried restarting on numerous occasions to no avail. I have run out of ideas, so if anyone has any any information would be helpful. Thanks!

EDIT

Posted results of dir:

enter image description here

Community
  • 1
  • 1
user1152440
  • 895
  • 2
  • 13
  • 25
  • 2
    Do "echo %PATH%" and make sure "c:\apache-ant\apache-ant-1.8.2\bin" is in there. By the way the correct way to view the ant version is ant -version. – Adam Bruss Feb 13 '12 at 15:17
  • C:\Users\Development Admin>echo %PATH% C:\Windows\system32;C:\Windows;C:\Program Files\Java\jdk1.6.0_29\bin;C:\Windows\ System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Program Files\Java\ jdk1.6.0_29\bin;%ANT_HOME%\bin – user1152440 Feb 13 '12 at 15:22
  • 2
    ANT_HOME is not being resolved. Change "%ANT_HOME%\bin" in the Path system environment variable to "c:\apache-ant\apache-ant-1.8.2\bin". – Adam Bruss Feb 13 '12 at 15:25
  • WORKS!, wow thank you very much. Being a tad new here, how would I "accept this answer" and give you a well deserved upvote? – user1152440 Feb 13 '12 at 15:29
  • You're welcome. I copied my comment and added it as an answer. You can accept the answer now as the right one. – Adam Bruss Feb 13 '12 at 15:38
  • I also created environment variables correctly, but ant was still not recognized. Funny thing, I just relaunched command prompt. – user12762628 Jan 22 '20 at 15:09
  • @AdamBruss' solution also did the trick for me :) ofc don't forget to restart the command prompt. complete set of Power Shell commands: [Environment]::SetEnvironmentVariable("JAVA_HOME", "C:\Program Files\Java\jdk1.8.0_231", "User") [Environment]::SetEnvironmentVariable("PATH", "C:\apache-ant-1.9.14\bin;C:\Program Files\Java\jdk1.8.0_231\bin", "User") – ghuroo Jan 28 '20 at 13:57

11 Answers11

54

ANT_HOME is not being resolved. Change %ANT_HOME%\bin in the Path system environment variable to c:\apache-ant\apache-ant-1.8.2\bin.

Mukul Goel
  • 8,387
  • 6
  • 37
  • 77
Adam Bruss
  • 1,654
  • 14
  • 18
15

I had a similar issue, but the reason that %ANT_HOME% wasn't resolving is that I had added it as a USER variable, not a SYSTEM one. Sorted now, thanks to this post.

Michu93
  • 5,058
  • 7
  • 47
  • 80
Joshua
  • 1,913
  • 1
  • 19
  • 31
  • I had this same issue. I don't recall seeing it with other versions, but I had it with ANT version 1.8.2. Thank you! – James Drinkard Oct 27 '14 at 21:48
  • This solved the issue for me for ANT version 1.9.4. Logging in and out had no effect. Once I changed the user variable to a system variable the `ant` command worked without having to relog. – Steve Feb 03 '15 at 20:58
6

create a script including the following; (replace the ant and jdk paths with whatever is correct for your machine)

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

run it in shell.

Cugomastik
  • 911
  • 13
  • 22
4

When Environment variables are changed log off and log in again so that it will be applied.

Desmond
  • 1,308
  • 1
  • 19
  • 27
3

I downloaded ant (http://ant.apache.org/bindownload.cgi), unzipped to my C drive, and used the windows 'doskey' command:

doskey ant=C:\apache-ant-1.9.6\bin\ant.bat $*

this will work as long as you use the same command console, to make it permanent is more difficult: http://darkforge.blogspot.com/2010/08/permanent-windows-command-line-aliases.html

wordsforthewise
  • 13,746
  • 5
  • 87
  • 117
2

Please follow these steps

  1. In User Variables

    Set VARIABLE NAME=ANT_HOME VARIABLE PATH =C:\Program Files\apache-ant-1.9.7

2.Edit User Variable PATH = %ANT_HOME%\bin

  1. Go to System Variables

    • Set Path =%ANT_HOME%\bin
User6
  • 83
  • 2
  • 9
1

Had the same problem. The solution is to add a \ at the end of %ANT_HOME%\bin so it became %ANT_HOME%\bin\

Worked for me. (Should be system var)

0

even with the environment variables set, I found that ant -version does not work in scripts. Try call ant -version

britt
  • 1
  • 1
0

Need to see whether you got ant folder moved by mistake or unknowingly. It is set in environment variables.I resolved this once as mentioned below.

I removed ant folder by mistake and placed in another folder.I went to command prompt and typed "path". It has given me path as "F:\apache-ant-1.9.4\". So I moved the ant back to F drive and it resolved the issue.

0

If none above helped anyone...My issue was that I was trying to use ant -version on a cmd prompt that I had already opened before I added apache-ant to the path.

As the cmd prompt was using the PATH it had when it was opened and not the new one (that had apache-ant) it wasn't finding it.

Opening a new cmd and running ant -version showed me I actually did have it installed correctly.

JamesS
  • 2,167
  • 1
  • 11
  • 29
0

I got same problem , what I did for fix :

  1. Open system environment variable
  2. Click on environment variable
  3. in user varaible -> edit path and then add C:\FolderWhereYouInstalled\ant\ant_1.8.4\bin
  4. Click ok
  5. Open cmd and type : ant -version

thanks, might help someone :)