Installing Ant

You need Ant to compile and run the example presented in the JBoss documentation. Ant is the standard build tool used by most open source Java projects and is widely being used in commercial settings as well. You need Ant version 1.4 or latter. You can download the 1.4 binaries for Ant from this link to the Apache/Jakarta website. If you have problems finding binaries at that location try the Ant home page which is located on the Apache/Jakarta website.

Once you have the Ant distribution unarchive it to create a jakarta-ant-1.4 directory. The Ant documentation is located in the docs/manual directory. You should start with the docs/manual/index.html file and browse through its contents if you want to use Ant. You won't need to know anything about Ant build scripts in order to compile and run the examples in the JBoss documentation. All we care about at this point is that you have Ant installed and availble in your executation path such that you can run ant from the command line. To do this you need the path to the jakarta-ant-1.4/bin directory in your PATH environment variable(or the equivalent construct for you OS). So for example, I have Ant installed in /usr/local/Java/Ant/jakarta-ant-1.4 and my PATH contains /usr/local/Java/Ant/jakarta-ant-1.4/bin. On a win32 platform with Ant installed in G:/tmp/jakarta-ant-1.4 you would need G:/tmp/jakarta-ant-1.4/bin in your PATH. Setup your PATH now.

You need the bin directory of a 1.3 JDK(Java development kit) in your path as well for access to the java interpreter and java compiler. You also typically need to set the JAVA_HOME environment variable to point to the location of a JDK 1.3 installation so that Ant can find the javac compiler. Your Ant installation may have been configured such that this is not necessary and you can try the following installation test without this set at first.

Test the Ant installation by opening a shell or command prompt. Next create a build.xml file in the current directory that contains the contents listed in the following figure:

Figure 1.1. Ant build.xml script for testing an Ant installation


<!-- Simple Ant build script to test an Ant installation -->
<project name="TestInstall" default="run" basedir=".">

  <target name="init">
    <available file="ASimpleHelloObject.java" property="ASimpleHelloObject"/>
  </target>

  <target name="ASimpleHelloObject" unless="ASimpleHelloObject" depends="init">
    <echo file="ASimpleHelloObject.java">
public class ASimpleHelloObject
{
    public static void main(String[] args)
    {
        System.out.println("ASimpleHelloObject.main was called");
    }
}
    </echo>
    <echo message="Wrote ASimpleHelloObject.java" />
  </target>

  <target name="compile" depends="ASimpleHelloObject">
    <javac destdir="." srcdir="." debug="on" classpath=".">
        <include name="ASimpleHelloObject.java"/>
    </javac>
  </target>

  <target name="run" depends="compile">
    <java classname="ASimpleHelloObject" classpath="." />
    <echo message="Ant appears to be successfully installed" />
  </target>

</project>

On a linux system with the build.xml file in /tmp you should see output like:


bash-2.04$ ant
Buildfile: build.xml

init:

ASimpleHelloObject:
     [echo] Wrote ASimpleHelloObject.java

compile:
    [javac] Compiling 1 source file to /tmp

run:
ASimpleHelloObject.main was called
     [echo] Ant appears to be successfully installed

BUILD SUCCESSFUL

Total time: 2 seconds

On a win32 system with the build.xml file in D:/temp you should see output like:


D:\temp>ant
Buildfile: build.xml

init:

ASimpleHelloObject:

compile:
    [javac] Compiling 1 source file to D:\temp

run:
ASimpleHelloObject.main was called
     [echo] Ant appears to be successfully installed

BUILD SUCCESSFUL

Total time: 2 seconds

If instead out see something like:


D:\temp>ant

Warning: JAVA_HOME environment variable is not set.
  If build fails because sun.* classes could not be found
  you will need to set the JAVA_HOME environment variable
  to the installation directory of java.

Buildfile: build.xml

init:

ASimpleHelloObject:
     [echo] Wrote ASimpleHelloObject.java

compile:
    [javac] Modern compiler is not available - using classic compiler
    [javac] Compiling 1 source file to D:\temp

BUILD FAILED

D:\temp\build.xml:22: Cannot use classic compiler, as it is not available A comm
on solution is to set the environment variable JAVA_HOME to your jdk directory.

Total time: 1 second

then you need to setup the JAVA_HOME environment to point to your JDK 1.3 installation.