Categories
Apache Ant Java

Apache Ant

ANT is the Java equivalent of Make. Once you create a javadoc.xml file, you can use it to generate the Javadocs instead of having to go through the Javadoc Gererating Wizard in Eclipse.

Environment Variable and PATH for Eclipse’s version of Ant

ANT_HOME=C:\Program Files\eclipse\plugins\org.apache.ant_1.8.3.v20120321-1730
;%ANT_HOME%\bin

Eclipse Ant Editor and Ant Viewer

Eclipse has two very cool features for building and running Ant files.

  1. In Eclipse, click Window > Show View > Ant.
  2. In the new Ant window, right-click on the root folder item, and click open in XML Editor. Eclipse’s built-in XML Editor displays syntax-formatted XML, and has a cool Design tab feature that allows you to manipulate the entities.

The Latest Version of Ant

You don’t have to download and install Ant. It’s bundled with Eclipse (albeit, its an not the latest version of Ant – v1.7). At the time of this writing, the latest version of Ant is v1.8.4.

If you install it, you’ll get a warning message when you try to change the Ant configuration in Eclipse (Windows > Preferences > Ant > Runtime > Ant Home…) – to point to the new ANT_HOME. Apparently the new installation is missing “tools.jar”, which Eclipse needs.

In Eclipse, Windows > Preferences > Ant; “Some tasks, such as “javac”, require the tools.jar library to be on the Ant runtime classpath to execute successfully.”

  1. To fix this, in Eclipse, navigate to Windows > Preferences > Ant > Runtime > Classpath > Global Entries.
  2. Click “Add external Jars…”.
  3. Type “C:\Program Files\Java\jdk1.7.0_21\lib\tools.jar”, and click “Open”.

Download and Install

At the time of this writing, the latest version of Ant is apache-ant-1.9.1.

  1. Download Apache Ant, and extract the zip file to C:\. It’ll end up with in C:\apache-ant-1.9.1.
  2. Set the “ANT_HOME” environment variable to “C:\apache-ant-1.9.1”.
  3. Path ;%ANT_HOME%\bin Make sure that you also the JAVA_HOME environment variable set to the JDK. This is required for running Ant. ..Note: You’d think that JAVA_HOME should point to the JRE, not to the JDK, but apparently that’s not the case. It should point to the JDK.
  4. Check your installation by opening a command line and typing “ant -version” into the commend line. The system should find the command ant and show the version number of your installed Ant.

I did this, and I got the following error:

“C:\Users\Chris>ant -version
Unable to locate tools.jar. Expected to find it in %JDK_HOME%\lib\tools.jar Apache Ant(TM) version 1.9.1 compiled on May 15 2013”

I fixed it by simply copying C:\Program Files\Java\jdk1.7.0_21\lib\tools.jar to C:\Program Files\Java\jre7\lib\.

Using Ant to build the docs from the Command Line

  1. Open a command prompt.
  2. Type: C:\Users\Chris\src\java_3rdParty>ant -f javadoc.xml

Using Ant to build the docs from the Run dialog

  1. Open the Run dialog by pressing the Windows Key + R (on the Kinesis Advantage keyboard, that’s Right Alt + R).

  2. Paste the following command line into the Open field, and the click OK.

    %ANT_HOME%\bin\ant -F %USERHOME%\src\java_3rdParty\javadoc.xml

  3. When the Permission dialog appears, just click OK.

Leave a Reply