Installing Apache Ant in Windows

Apache Ant is a Java-based build tool. To install ant, please follow the instructions.

1. Download Ant.

2. Unzip downloaded file.

3. Rename the unzipped directory to “ant”. You can choose another directory name, remember that name is not too long. A long name will create a problem in Win95, Win98 and WinMe.

On these systems, the script used to launch Ant will have problems if ANT_HOME is a long filename (i.e. a filename which is not of the format known as “8.3″). This is due to limitations in the OS’s handling of the "for" batch-file statement. It is recommended, therefore, that Ant be installed in a short, 8.3 path, such as C:\Ant.

4. Set ANT_HOME environment variable.

My Computer -> Advanced System Properties -> Environment Variable.
Now on the system variable click on New to add a new Environment Variable.

5. Update Path environment variable. e.g.(oldpath;%ANT_HOME%/bin;)

You don’t require to setup CLASSPATH because of the following reasons

  1. Do not ever set CLASSPATH. Ant does not need it, it only causes confusion and breaks things.
  2. If you ignore the previous rule, do not ever, ever, put quotes in the CLASSPATH, even if there is a space in a directory. This will break Ant, and it is not needed.
  3. If you ignore the first rule, do not ever, ever, have a trailing backslash in a CLASSPATH, as it breaks Ant’s ability to quote the string. Again, this is not needed for the correct operation of the CLASSPATH environment variable, even if a DOS directory is to be added to the path.
  4. You can stop Ant using the CLASSPATH environment variable by setting the -noclasspath option on the command line. This is an easy way to test for classpath-related problems.

To test if Ant is installed successfully, go to command prompt and type ant-h. It will show you help regarding ant usages.

Related Post

‘ant’ is not recognized as an internal or external command, operable program or batch file.
Installing tomcat in ubuntu/linux
java.lang.ClassNotFoundException: org.springframework.web.context.ContextLoaderListener
Setting up j2ee developer environment in ubuntu/linux
javax.servlet.ServletException: javax.naming.NameNotFoundException: Name comp is not bound in this Context

Comments

33 Responses to “Installing Apache Ant in Windows”

  1. Umesh on February 12th, 2009 12:46 pm

    Hello Sir,
    i followed the all above steps but getting Error ant is not recognized external or enternal command,could you please let me know any other way to trace the issue;

  2. Amit on February 27th, 2009 11:05 am

    Have you got it fixed?

  3. danielle on April 5th, 2009 12:29 pm

    Hello,
    I’ve been trying to install ant on my windows XP and I can’t make it work.. I’ve follow every step and it keeps saying that ant is not recognized external or internal command….
    What could be the problem?

  4. Amit on April 7th, 2009 12:26 am

    Open command prompt ant type following
    user> echo %path%
    check if it show you
    C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;c:\ant\bin;C:\Program Fi
    les\Java\jdk1.6.0_02\bin;

    It must be showing ant in your path. If it doesn’t then you need to open your system environment variable and set ant in your path.
    After setting it open new command prompt window.

  5. danielle on April 13th, 2009 11:26 am

    Thanks.. I fixed it.. it was some other problem with the variables.. but it works fine now.. thanks..

  6. keith mountaine on May 20th, 2009 8:04 pm

    hey i am a bit lost i have downloaded ant and i have unzipped the flie to my D drive and called it and i am a bit lost with step 4

    Set ANT_HOME environment variable.

    My Computer -> Advanced System Properties -> Environment Variable.
    Now on the system variable click on New to add a new Environment Variable. i have done all this and a tab comes up and ask for the veriable name and variable value what should i put i there?

    and i have changed the path to have D:\ant in it does it also need too have the java\jdk1.6.02\bin; in it to make it work??

    i have gone into my compters properties

  7. keith mountaine on May 20th, 2009 8:08 pm

    sorry there are a few mistakes in the last post i have called the unzipped file ant and the last sentance should not be there im just a bit tired ha ha

  8. Amit on May 20th, 2009 8:39 pm

    1. Variable name must be “ANT_HOME” (without quotes).
    2. JDK is required and JAVA_HOME should be pointing to current installed JDK. Java may be required as you might be using javac command in some ant task.

  9. keith mountaine on May 20th, 2009 10:48 pm

    when you say it should be pointing too jdk do you mean that the veriable value should be something like this?? D:\Windows\system32;D:\Windows;D:\Windows\System32\Wbem;d:\ant\bin;d:\Program Files\Java\jdk1.6.0_13

    or do i have the wrong thing??

  10. keith mountaine on May 21st, 2009 9:52 pm

    any help would be great as i am using this for my end of year project in college

  11. JP on August 10th, 2009 3:53 pm

    can we set windows system property values through ant script?. can we change it randomly?

  12. abhishek on August 24th, 2009 7:54 pm

    hey this is gr8.. thanks

  13. Venkat on October 24th, 2009 12:52 pm

    Hi,
    Thanks for the step by step guidance

  14. Mason Simon on November 29th, 2009 6:55 am

    I made an installer called WinAnt to automate these steps. You can download it from http://code.google.com/p/winant/

  15. kaustav on December 29th, 2009 1:50 pm

    i dont hav admin right’s in my system………so can i add another path variable in my user variable C:\ANT_HOME\bin this ?

    pls help………… :)

  16. Laxman on February 28th, 2010 1:23 pm

    For windows..

    Assume Ant is installed in c:\ant\. The following sets up the environment:

    set ANT_HOME=c:\ant
    set JAVA_HOME=c:\jdk-1.5.0.05
    set PATH=%PATH%;%ANT_HOME%\bin

    For unix/linux(bash)

    Assume Ant is installed in /usr/local/ant. The following sets up the environment:

    export ANT_HOME=/usr/local/ant
    export JAVA_HOME=/usr/local/jdk-1.5.0.05
    export PATH=${PATH}:${ANT_HOME}/bin

    For linux/unix(csh)

    setenv ANT_HOME /usr/local/ant
    setenv JAVA_HOME /usr/local/jdk/jdk-1.5.0.05
    set path=( $path $ANT_HOME/bin )

    Try thzz …it definitely works..

  17. Lavi on March 15th, 2010 7:08 pm

    thanx mason..windows installer has been very handy to get d work done soon!

  18. Gaurav on March 24th, 2010 6:06 pm

    Thanks a lot for your help

  19. Diptesh Patel on April 7th, 2010 5:21 pm

    This is an extra ordinary help….

    thanks a lot guys..

  20. roji on May 1st, 2010 9:21 pm

    Thank’s for your article. :-bd

  21. gcat on June 21st, 2010 8:44 pm

    hi
    Thanks for your gr8 article
    i have one doubt
    i have put variable name= ANT_HOME
    what will be varialbe value?

    thanx in advance?

  22. Amit on June 21st, 2010 10:56 pm

    This is the root location of the directory where you unzipped ant. e.g. if you unzipped ant into c drive then your ANT_HOME variable is “c:\ant”

  23. gcat on June 22nd, 2010 8:16 pm

    tnx for the reply
    it works now.

  24. sunny on November 26th, 2010 12:41 am

    sir,
    Your four steps to install ant are great!
    i have tried all four steps and checked in command prompt which shows

    c:\windows\system32;c:\windows;c:\windows\system32\wbem;c:\windows\system32\windowsPowershell\v1.0\

    am i done with that or any error is there in my install.
    plz help

  25. Amit on November 26th, 2010 8:50 am

    It seems that you have missed some step. Make sure that you have set ANT_HOME environment variable to the location where you unzipped ant and you must update path variable as explained in step 5.

    In case if it still doesn’t work for you. Let me know exact directory location, value of ANT_HOME and path variable.

  26. sunny on November 26th, 2010 4:57 pm

    Amit sir,
    thanks for your kind help
    When i wrote echo %path% cmd shows the following location:
    C:\windows\system32;c:\windows;c:\windows\system32\wbem;c:\windows\system32\windowsPowershell\v1.0\;c:\rogram files\java\jre6\bin

    but when i write javac,it clearly shows that the javac is not recognised as internal or external command.

    My user path is C:\Program Files\Java\jre6\bin

    and classpath is same wich is C:\Program Files\Java\jre6\bin for java

    and my system variable for ANT_HOME is D:\stallioncorps\apache-ant-1.8.1-bin.

    my cell no. is 0-9896658668.
    plz help i m a rookie.

  27. Amit on November 27th, 2010 10:12 am

    I guess there is some typo in your class path.. see it carefully it is “c:\rogram files\java\jre6\bin”. “P” is missing. Also close your command prompt and then open again after setting path.

  28. sandeep on December 14th, 2010 5:05 pm

    Hi,

    You can find a good tutorial here if you still have problem.

    http://javawithbrain.blogspot.com/2010/12/installing-apache-ant.html

    take a look.

  29. Ash on January 11th, 2011 3:34 pm

    winant tool is excellent.

  30. Fran on May 31st, 2011 2:25 am

    I found an error in the instructions above – “ant-h” fails as a test, but “ant -h” works fine. It might be good to update the instructions above.
    Otherwise, this was very helpful, so thank you.

  31. Megha on July 12th, 2011 2:44 pm

    hi
    i want to install ant on my windows XP i set the PATH as told in above.

    ANT_HOME = C:\ant
    PATH = %PATH%;C:\ant\bin
    then also when i run the ant-h it display internal or external command

  32. Pramod on July 28th, 2011 12:00 pm

    I followed the steps and it works well. Thanks

  33. mohit on December 28th, 2011 5:58 pm

    thanks alot for the article helped alot…..

Leave a Reply