Oracle GlassFish Server 3.0.1 Application Development Guide

# Setting Up Your Ant Environment

To set up your Ant environment for using GlassFish Server Ant tasks, you can either define the ANT_OPTS environment variable or define a target. In both these cases, you must also set the classpath to point to the sun-appserv-ant.jar file.

## Defining the ANT_OPTS Variable

To define the ANT_OPTS environment variable on UNIX systems, use the following commands, where \${ASINSTALLDIR} is an environment variable defined to point to the GlassFish Server installation directory.

export ANT_OPTS="-Djava.library.path\${ASINSTALLDIR}/modules"
export CLASSPATH=\${CLASSPATH};\${ASINSTALLDIR}/modules/sun-appserv-ant.jar

To define the ANT_OPTS environment variable on Windows systems, use the following commands, where %ASINSTALLDIR% is an environment variable defined to point to the GlassFish Server installation directory.

set ANT_OPTS="-Djava.library.path=%ASINSTALLDIR%\modules"
set CLASSPATH=%CLASSPATH%;%ASINSTALLDIR%\modules\sun-appserv-ant.jar

## Defining a Target

The following target element defines the GlassFish Server Ant tasks and references the sun-appserv-ant.jar file. You can include this target in your build.xml file. The \${asinstalldir} in the classpath element refers to the GlassFish Server installation directory.

<target name="as-ant-init">
<classpath path="\${asinstalldir}/lib/sun-appserv-ant.jar" />
</target>

Targets that use the GlassFish Server Ant tasks then can use the as-ant-init target as a dependency. For example:

<target name="create-some-jdbc-resource" depends="as-ant-init">
...
</target>

Ant resolves properties from top to bottom in Ant build files. If you define the GlassFish Server Ant tasks at the project level, make sure that any properties used within the task definitions have been resolved before the task definitions. For example, the following snippet defines the sun-appserv-admin task at the project level:

<?xml version="1.0" encoding="UTF-8"?>