Oracle GlassFish Server 3.0.1 Application Development Guide

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">
   <taskdef name="sun-appserv-deploy"
      classname="org.apache.tools.ant.taskdefs.optional.sun.appserv.DeployTask" />
   <taskdef name="sun-appserv-undeploy"
      classname="org.apache.tools.ant.taskdefs.optional.sun.appserv.UndeployTask" />
   <taskdef name="sun-appserv-component"
      classname="org.apache.tools.ant.taskdefs.optional.sun.appserv.ComponentTask" />
   <taskdef name="sun-appserv-admin"
      classname="org.apache.tools.ant.taskdefs.optional.sun.appserv.AdminTask" />
   <taskdef name="sun-appserv-jspc"
      classname="org.apache.tools.ant.taskdefs.optional.sun.appserv.SunJspc" />
   <taskdef name="sun-appserv-update"
      classname="org.apache.tools.ant.taskdefs.optional.sun.appserv.UpdateTask" />
   <taskdef name="sun-appserv-instance"
      classname="org.apache.tools.ant.taskdefs.optional.sun.appserv.InstanceTask" />
    <taskdef name="wsgen" classname="com.sun.tools.ws.ant.WsGen" />
    <taskdef name="wsimport" classname="com.sun.tools.ws.ant.WsImport" />
   <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"?>
<project name="glassfish-admin-ant-tasks" default="default">
    <property name="asinstalldir" value="c:/glassfishv3/glassfish" />
    <taskdef name="sun-appserv-admin"
        classname="org.apache.tools.ant.taskdefs.optional.sun.appserv.AdminTask"
        classpath="${asintalldir}/modules/sun-appserv-ant.jar" />
    ...
</project>