How To Install ANT on Windows

Author: Steven Neiland
Published:

Warning: This blog entry was written two or more years ago. Therefore, it may contain broken links, out-dated or misleading content, or information that is just plain wrong. Please read on with caution.

As I'm currently in the process of building a new developer machine I thought I'd take the time to document installing one of my favorite tools ANT.

ANT (Another Neat Tool) is a build tool which allows you to automate the process of building, testing and deploying a software project. As it is a java tool it runs anywhere, but since I work mainly on windows I'm going to detail how to install it on windows.

Step 1: Install Java JDK

The first step to installing ANT is actually to install the java JDK. Go to the Oracle JDK Download Page and download the 32-bit JDK installer (I have encountered problems with the 64-bit version in the past which may or may not have been fixed).

Run the installer and note the install directory for later. My own install ended up at "c:\Program Files\java\jdk[version number]"

Step 2: Download & Extract The Latest ANT Build

With java installed go ahead and download the latest ANT build zip file from the ANT Download Page. Then simply extract the zip file to a convenient location. I placed mine at "C:\ant".

Step 3: Setup System Variables

Now we need to setup three system variables.

  • "ANT_HOME" : The location we extracted the ANT zip file to.
  • "JAVA_HOME" : The java JDK location.
  • "PATH" : The existing PATH value plus the location of the ANT bin folder.

For my install I used the following values.

  • "ANT_HOME" : c:\ant
  • "JAVA_HOME" : c:\Program Files\Java\jdk1.6.0_24
  • "PATH" : %PATH%;%ANT_HOME%\bin

To check to see if these are already defined open a command prompt and run the following commands.

echo %JAVA_HOME%
echo %ANT_HOME%
echo %PATH%

If they are not already setup we have two options to define them.

GUI Setup

To use the windows gui to setup these variables open "control panel > system > advanced system settings". Select the "advanced" tab and click on "environment variables".

Add two new user variables "ANT_HOME" and "JAVA_HOME" with their respective values.

Then edit the system variable "PATH" and add ";c:\ant\bin" to it.

Command Prompt Setup

A simpler way to accomplish the same thing is to open a command prompt window (with admin rights) and run the following commands. Remember to modify the values to match your configuration.

set ANT_HOME=c:\ant
set JAVA_HOME=c:\Program Files\Java\jdk1.6.0_24
set PATH=%PATH%;%ANT_HOME%\bin

Step 4: Restart And Test

To test if ant is installed correctly all we need to do is open a command prompt and run the "ant" command. If everything is setup correctly you should see this message.

C:\Windows\System32>ant
Buildfile: build.xml does not exist!
Build Failed

What this means is that ant is running but there currently is no buildfile (build.xml) for it to run. This is exactly what you would expect to happen for a new install with no software projects with build files to run.

Fix Missing "tools.jar" Error

If when you ran the ant command you get the following error you need to check that the JAVA_HOME variable is pointing to the JDK directory and not the JRE directory.

Note how the tools.jar path reads "jre6" and not "jdk6".

C:\>ant
Unable to locate tools.jar. Expected to find it in C:\Program Files\Java\jre6\li
b\tools.jar
Buildfile: build.xml does not exist!
Build failed

So there you have it, ANT installed and running on windows. In a later post I'll show you how to hook up eclipse to use it.

Related Blog Postings

Reader Comments

Tvk Reddy's Gravatar
Tvk Reddy
Friday, July 5, 2013 at 1:02:38 AM Coordinated Universal Time

Thanks very much... very clearly given !!

Jel's Gravatar
Jel
Friday, May 23, 2014 at 5:07:15 AM Coordinated Universal Time

It worked!thanks^^

pidjoma's Gravatar
pidjoma
Saturday, April 23, 2016 at 6:19:15 PM Coordinated Universal Time

It is very clear, thank u very much

  • Please keep comments on-topic.
  • Please do not post unrelated questions or large chunks of code.
  • Please do not engage in flaming/abusive behaviour.
  • Comments that contain advertisments or appear to be created for the purpose of link building, will not be published.

Archives Blog Listing