17

I have installed ant(apache-ant-1.7.0). But when i run the ant command in dos command prompt, it says

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

where i'm going wrong.

Gangnus
  • 24,044
  • 16
  • 90
  • 149
Srinivasan
  • 11,718
  • 30
  • 64
  • 92

8 Answers8

38

That just means it's not on the path.

Edit your PATH environment variable to include Ant's "bin" directory. The exact steps for editing your path with depend on your operating system, but for example on XP:

  • Bring up Explorer (Windows-E)
  • Right-click on "My Computer" and select "Properties"
  • On the "Advanced" tab, click on "Environment Variables"
  • If the set of "user variables" already contains a PATH entry, edit that. Otherwise create a new entry. (If you want it to affect all users, set it as a system environment variable.)
  • Add the Ant bin directory without any quotes. Use a semi-colon to separate it from another entry. For example, you might have:

    c:\Program Files\Utils;c:\Program Files\Ant 1.7\bin
    
  • Start a new Command Prompt to see the changes (they won't affect existing windows)
Jon Skeet
  • 1,421,763
  • 867
  • 9,128
  • 9,194
  • I have already set the bin directory to the PATH variable. but it is working when i logon as administrator. when i login as some user account, it throws error like this. – Srinivasan Oct 19 '09 at 06:10
  • 2
    Then that suggests you've set the PATH variable just for the administrator. Either set it for the individual user, or for the system. – Jon Skeet Oct 19 '09 at 06:18
  • I set it(PATH) in the System variable by administrator login. When i enter echo %path%(from the administrator account) in the command prompt, ant path is included in the PATH system variable. But when i login in my login and enter echo %path%, it does not include the ant path. Can i restart the system after PATH setting? – Srinivasan Oct 19 '09 at 06:25
  • 1
    I would have expected logging in again from scratch to be okay, but just switching user wouldn't. But try a reboot and see if that fixes it for you, certainly. – Jon Skeet Oct 19 '09 at 06:39
  • 1
    Thank you very much for "they won't affect existing windows". – Min Naing Oo Nov 28 '13 at 08:42
14

For anyone that comes across this article:
Always remember, don't put a space after each semicolon.


Good:
C:\Ninja;C:\ant

Bad:
C:\Ninja; C:\ant

RichardJohnn
  • 654
  • 9
  • 24
5

In windows:

  • ANT_HOME environment variable should be set to your ant install dir. If you haven't such, download ant and unzip it.

In Jenkins configuration

  • %ANT_HOME%\bin should be added to PATH
  • Go to Jenkins / Manage Jenkins / Configure System / Ant Installation.
    • Uncheck Install Automatically
    • Give name for Ant (AntName)
    • Put ant install dir into ANT_HOME

In Jenkins project

  • Got to Project/Configure/Build/Invoke Ant. (Add Build Step/Invoke Ant if you haven't any). In Ant Version change Default to AntName (set by you in the Jenkins configuration)
Gangnus
  • 24,044
  • 16
  • 90
  • 149
3

Also do not put a space at end of your path entry.

Good: C:\Ninja;C:\ant

Bad: C:\Ninja;C:\ant(sp)

...where (sp) represents a white space or blank. I had this and couldn't figure it out until I saw RichardJohnn's reply and then found it at the end.

Chadwick
  • 12,555
  • 7
  • 49
  • 66
Seth
  • 39
  • 1
2

Don't use Windows GUI for creating environment variables because they can mess up with the system. Easiest and best way to create a variable is creating them as local with a command script. This way they will be local and won't interfare with your system, and easier then using GUI :)

Open up a blank notepad, type the following (in case you are interested in building a Java project I added a JAVA_HOME variable as well). 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 the script and check the location with echo %ANT_HOME%.

Cugomastik
  • 911
  • 13
  • 22
2

Two Important Notes on Windows Environment Variables:

  • Keep in mind that some processes run at the System level, as opposed to the User level. This is especially true of Services. So if you have a Service that is throwing this error, you may need to edit the System %PATH% variable, not the User one.
  • Each process stores a local cache of the environment variables at process launch-time. This means you need to restart the process/service after you make these changes. This includes cmd.exe
Jonathan
  • 6,741
  • 7
  • 52
  • 69
0

Step 1: Navigate to Advance System Setting, and then click on the advance tab there, click on environment variable button, here you can create environment variable

Step 2: In the user variable create a new variable say "ANT_HOME" and provide a path to it: For example: VARIABLE_NAME = ANT_HOME VARIABLE_value = "D:\apache-ant-1.9.6"

Step 3: Now append the path of the Ant home directory till bin in the path variable of the system variable

Now open the cmd promt and type ant, if it is still unrecognized try running the cmd promt using admin mode, it will surely work

-1

The best way to build using ANT is in Eclipse. just type Ant in quick access box in Eclipse, Select New Java project from existing build file option. Select the XML file and the Eclipse will build it for you.

chetan
  • 411
  • 1
  • 5
  • 8