Oracle GlassFish Server 3.0.1 Application Development Guide

Chapter 3 Using Ant with GlassFishTM Server

The Oracle GlassFish Server provides server-specific Ant tasks, which are described in the following sections:

GlassFish Server is compatible with Apache Ant versions 1.6.5 or greater. If you don't have Ant installed, you can download it from the Update Tool. The Apache Ant Build Tool add-on component supplies Ant version 1.7.1. For more information about the Update Tool, see Update Tool in Oracle GlassFish Server 3.0.1 Administration Guide.

For more information about Ant, see the Apache Software Foundation web site at http://ant.apache.org/.

For information about standard Ant tasks, see the Ant documentation at http://ant.apache.org/manual/.


Note –

Variables in the examples in this chapter, such as ${asinstalldir}, reference values defined in build.xml or properties files.


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">
   <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>

GlassFish Server Ant Tasks

Use the Ant tasks provided by the GlassFish Server for assembling, deploying, and undeploying modules and applications, and for configuring the server. The tasks are as follows:

The sun-appserv-deploy Task

Deploys any of the following to a local or remote GlassFish Server instance.

Subelements of sun-appserv-deploy

The following table describes subelements for the sun-appserv-deploy task. These are objects upon which this task acts.

Table 3–1 The sun-appserv-deploy Subelements

Element 

Description 

The server Subelement

A GlassFish Server instance 

The component Subelement

A component to be deployed 

The fileset Subelement

A set of component files that match specified parameters 

Attributes of sun-appserv-deploy

The following table describes attributes for the sun-appserv-deploy task.

Table 3–2 The sun-appserv-deploy Attributes

Attribute 

Default 

Description 

file

none 

(optional if a component or fileset subelement is present, otherwise required) The component to deploy. If this attribute refers to a file, it must be a valid archive. If this attribute refers to a directory, it must contain a valid archive in which all components have been exploded. If upload is set to false, this must be an absolute path on the server machine.

name

file name without extension 

(optional) The display name for the component being deployed. 

force

true

(optional) If true, the component is overwritten if it already exists on the server. If false, sun-appserv-deploy fails if the component exists.

retrievestubs

client stubs not saved 

(optional) The directory where client stubs are saved. This attribute is inherited by nested component elements.

precompilejsp

false

(optional) If true, all JSP files found in an enterprise application (.ear) or web application (.war) are precompiled. This attribute is ignored for other component types. This attribute is inherited by nested component elements.

verify

false

(optional) If true, syntax and semantics for all deployment descriptors are automatically verified for correctness. This attribute is inherited by nested component elements.

contextroot

file name without extension 

(optional) The context root for a web module (WAR file). This attribute is ignored if the component is not a WAR file. 

dbvendorname

sun-ejb-jar.xml entry

(optional) The name of the database vendor for which tables can be created. Allowed values are javadb, db2, mssql, mysql, oracle, postgresql, pointbase, derby (also for CloudScape), and sybase, case-insensitive.

If not specified, the value of the database-vendor-name attribute in sun-ejb-jar.xml is used.

If no value is specified, a connection is made to the resource specified by the jndi-name subelement of the cmp-resource element in the sun-ejb-jar.xml file, and the database vendor name is read. If the connection cannot be established, or if the value is not recognized, SQL-92 compliance is presumed.

For details, see Generation Options for CMP.

createtables

sun-ejb-jar.xml entry

(optional) If true, causes database tables to be created for beans that need them. If false, does not create tables. If not specified, the value of the create-tables-at-deploy attribute in sun-ejb-jar.xml is used.

For details, see Generation Options and Generation Options for CMP.

dropandcreatetables

sun-ejb-jar.xml entry

(optional) If true, and if tables were automatically created when this application was last deployed, tables from the earlier deployment are dropped and fresh ones are created.

If true, and if tables were not automatically created when this application was last deployed, no attempt is made to drop any tables. If tables with the same names as those that would have been automatically created are found, the deployment proceeds, but a warning indicates that tables could not be created.

If false, settings of create-tables-at-deploy or drop-tables-at-undeploy in the sun-ejb-jar.xml file are overridden.

For details, see Generation Options and Generation Options for CMP.

uniquetablenames

sun-ejb-jar.xml entry

(optional) If true, specifies that table names are unique within each GlassFish Server domain. If not specified, the value of the use-unique-table-names property in sun-ejb-jar.xml is used.

For details, see Generation Options for CMP.

enabled

true

(optional) If true, enables the component.

deploymentplan

none 

(optional) A deployment plan is a JAR file containing GlassFish Server descriptors. Use this attribute when deploying an EAR file that lacks GlassFish Server descriptors. 

availabilityenabled

false

(optional) If true, enables high availability features, including persistence of HTTP sessions and checkpointing of the stateful session bean state.

generatermistubs

false

(optional) If true, generates the static RMI-IIOP stubs and puts them in the client JAR file.

upload

true

(optional) If true, the component is transferred to the server for deployment. If the component is being deployed on the local machine, set upload to false to reduce deployment time. If a directory is specified for deployment, upload must be false.

virtualservers

default virtual server only 

(optional) A comma-separated list of virtual servers to be deployment targets. This attribute applies only to application (.ear) or web (.war) components and is ignored for other component types. This attribute is inherited by nested server elements.

user

admin

(optional) The user name used when logging into the GlassFish Server administration instance. This attribute is inherited by nested server elements.

passwordfile

none 

(optional) File containing passwords. The password from this file is retrieved for communication with the GlassFish Server administration instance. This attribute is inherited by nested server elements.

host

localhost

(optional) Target server. When deploying to a remote server, use the fully qualified host name. This attribute is inherited by nested server elements.

port

4848

(optional) The administration port on the target server. This attribute is inherited by nested server elements.

target

name of default instance 

(optional) Target server instance. This attribute is inherited by nested server elements.

asinstalldir

see description 

(optional) The installation directory for the local GlassFish Server installation, which is used to find the administrative classes. If not specified, the command checks if the asinstalldir parameter has been set. Otherwise, administrative classes must be in the system classpath.

Examples of sun-appserv-deploy

Here is a simple web application deployment script with many implied attributes:

<sun-appserv-deploy
file="${assemble}/simpleapp.war"
passwordfile="${passwordfile}" />

Here is an equivalent script showing all the implied attributes:

<sun-appserv-deploy
 file="${assemble}/simpleapp.war"
 name="simpleapp"
 force="true"
 precompilejsp="false"
 verify="false"
 upload="true"
 user="admin"
 passwordfile="${passwordfile}"
 host="localhost"
 port="4848"
 target="${default-instance-name}"
 asinstalldir="${asinstalldir}" />

This example deploys multiple components to the same GlassFish Server instance running on a remote server:

<sun-appserv-deploy passwordfile="${passwordfile}" host="greg.oracle.com"
		 asinstalldir="/opt/glassfish" >
 <component file="${assemble}/simpleapp.ear"/>
 <component file="${assemble}/simpleservlet.war"
	 contextroot="test"/>
 <component file="${assemble}/simplebean.jar"/>
</sun-appserv-deploy>

This example deploys multiple components to two GlassFish Server instances running on remote servers. In this example, both servers are using the same admin password. If this were not the case, each password could be specified in the server element.

<sun-appserv-deploy passwordfile="${passwordfile}" asinstalldir="/opt/glassfish" >
 <server host="greg.oracle.com"/>
 <server host="joe.oracle.com"/>
 <component file="${assemble}/simpleapp.ear"/>
 <component file="${assemble}/simpleservlet.war"
	 contextroot="test"/>
 <component file="${assemble}/simplebean.jar"/>
</sun-appserv-deploy>

This example deploys the same components as the previous example because the three components match the fileset criteria, but note that it is not possible to set some component-specific attributes. All component-specific attributes (name and contextroot) use their default values.

<sun-appserv-deploy passwordfile="${passwordfile}" host="greg.oracle.com"
		 asinstalldir="/opt/glassfish" >
 <fileset dir="${assemble}" includes="**/*.?ar" />
</sun-appserv-deploy>

The sun-appserv-undeploy Task

Undeploys any of the following from a local or remote GlassFish Server instance.

Subelements of sun-appserv-undeploy

The following table describes subelements for the sun-appserv-undeploy task. These are objects upon which this task acts.

Table 3–3 The sun-appserv-undeploy Subelements

Element 

Description 

The server Subelement

A GlassFish Server instance 

The component Subelement

A component to be deployed 

The fileset Subelement

A set of component files that match specified parameters 

Attributes of sun-appserv-undeploy

The following table describes attributes for the sun-appserv-undeploy task.

Table 3–4 The sun-appserv-undeploy Attributes

Attribute 

Default 

Description 

name

file name without extension 

(optional if a component or fileset subelement is present or the file attribute is specified, otherwise required) The display name for the component being undeployed.

file

none 

(optional) The component to undeploy. If this attribute refers to a file, it must be a valid archive. If this attribute refers to a directory, it must contain a valid archive in which all components have been exploded. 

droptables

sun-ejb-jar.xml entry

(optional) If true, causes database tables that were automatically created when the bean(s) were last deployed to be dropped when the bean(s) are undeployed. If false, does not drop tables.

If not specified, the value of the drop-tables-at-undeploy attribute in sun-ejb-jar.xml is used.

For details, see Generation Options and Generation Options for CMP.

cascade

false

(optional) If true, deletes all connection pools and connector resources associated with the resource adapter being undeployed.

If false, undeployment fails if any pools or resources are still associated with the resource adapter.

This attribute is applicable to connectors (resource adapters) and applications with connector modules. 

user

admin

(optional) The user name used when logging into the GlassFish Server administration instance. This attribute is inherited by nested server elements.

passwordfile

none 

(optional) File containing passwords. The password from this file is retrieved for communication with the GlassFish Server administration instance. This attribute is inherited by nested server elements.

host

localhost

(optional) Target server. When deploying to a remote server, use the fully qualified host name. This attribute is inherited by nested server elements.

port

4848

(optional) The administration port on the target server. This attribute is inherited by nested server elements.

target

name of default instance 

(optional) Target server instance. This attribute is inherited by nested server elements.

asinstalldir

see description 

(optional) The installation directory for the local GlassFish Server installation, which is used to find the administrative classes. If not specified, the command checks to see if the asinstalldir parameter has been set. Otherwise, administrative classes must be in the system classpath.

Examples of sun-appserv-undeploy

Here is a simple application undeployment script with many implied attributes:

<sun-appserv-undeploy name="simpleapp" passwordfile="${passwordfile}" />

Here is an equivalent script showing all the implied attributes:

<sun-appserv-undeploy
 name="simpleapp"
 user="admin"
 passwordfile="${passwordfile}"
 host="localhost"
 port="4848"
 target="${default-instance-name}"
 asinstalldir="${asinstalldir}" />

This example demonstrates using the archive files (EAR and WAR, in this case) for the undeployment, using the component name (for undeploying the EJB component in this example), and undeploying multiple components.

<sun-appserv-undeploy passwordfile="${passwordfile}">
 <component file="${assemble}/simpleapp.ear"/>
 <component file="${assemble}/simpleservlet.war"/>
 <component name="simplebean" />
</sun-appserv-undeploy>

As with the deployment process, components can be undeployed from multiple servers in a single command. This example shows the same three components being removed from two different instances of the GlassFish Server. In this example, the passwords for both instances are the same.

<sun-appserv-undeploy passwordfile="${passwordfile}">
 <server host="greg.oracle.com"/>
 <server host="joe.oracle.com"/>
 <component file="${assemble}/simpleapp.ear"/>
 <component file="${assemble}/simpleservlet.war"/>
 <component name="simplebean" />
</sun-appserv-undeploy>

The sun-appserv-instance Task

Starts, stops, restarts, creates, or removes GlassFish Server instances.

Subelements of sun-appserv-instance

The following table describes subelements for the sun-appserv-instance task. These are objects upon which this task acts.

Table 3–5 The sun-appserv-instance Subelements

Element 

Description 

The server Subelement

A GlassFish Server instance 

Attributes of sun-appserv-instance

The following table describes attributes for the sun-appserv-instance task.

Table 3–6 The sun-appserv-instance Attributes

Attribute 

Default 

Description 

action

none 

The control command for the target server instance. Valid values are start, stop, create, and delete. A restart sends the stop command followed by the start command. The restart command is not supported on Windows.

debug

false

(optional) Deprecated. If action is set to start, specifies whether the server starts in debug mode. This attribute is ignored for other values of action. If true, the instance generates additional debugging output throughout its lifetime. This attribute is inherited by nested server elements.

config

none 

(optional, applicable only if action is create) The configuration for the new stand-alone instance.

The configuration must exist and must not be default-config or an already referenced stand-alone configuration (including the administration server configuration server-config).

property

none 

(optional, applicable only if action is create) Defines system properties for the server instance. These properties override port settings in the server instance’s configuration. The following properties are defined: http-listener-1-port, http-listener-2-port, orb-listener-1-port, SSL-port, SSL_MUTUALAUTH-port, JMX_SYSTEM_CONNECTOR_port.

System properties can be changed after instance creation using the system property commands. For details, see the Oracle GlassFish Server 3.0.1 Reference Manual.

user

admin

(optional) The user name used when logging into the GlassFish Server administration instance. This attribute is inherited by nested server elements.

passwordfile

none 

(optional) File containing passwords. The password from this file is retrieved for communication with the GlassFish Server administration instance. This attribute is inherited by nested server elements.

host

localhost

(optional) Target server. If it is a remote server, use the fully qualified host name. This attribute is inherited by nested server elements.

port

4848

(optional) The administration port on the target server. This attribute is inherited by nested server elements.

instance

name of default instance 

(optional) Target server instance. This attribute is inherited by nested server elements.

asinstalldir

see description 

(optional) The installation directory for the local GlassFish Server installation, which is used to find the administrative classes. If not specified, the command checks to see if the asinstalldir parameter has been set. Otherwise, administrative classes must be in the system classpath.

Examples of sun-appserv-instance

This example starts the local GlassFish Server instance:

<sun-appserv-instance action="start" passwordfile="${passwordfile}"
 instance="${default-instance-name}"/>

Here is an equivalent script showing all the implied attributes:

<sun-appserv-instance
 action="start"
 user="admin"
 passwordfile="${passwordfile}"
 host="localhost"
 port="4848"
 instance="${default-instance-name}"
 asinstalldir="${asinstalldir}" />

Multiple servers can be controlled using a single command. In this example, two servers are restarted, and in this case each server uses a different password:

<sun-appserv-instance action="restart"
	 instance="${default-instance-name}"/>
<server host="greg.oracle.com" passwordfile="${password.greg}"/>
 <server host="joe.oracle.com" passwordfile="${password.joe}"/>
</sun-appserv-instance>

This example creates a new GlassFish Server instance:

<sun-appserv-instance
 action="create" instanceport="8080"
 passwordfile="${passwordfile}"
 instance="development" />

Here is an equivalent script showing all the implied attributes:

<sun-appserv-instance
 action="create"
 instanceport="8080"
 user="admin"
 passwordfile="${passwordfile}"
 host="localhost"
 port="4848"
 instance="development"
 asinstalldir="${asinstalldir}" />

Instances can be created on multiple servers using a single command. This example creates a new instance named qa on two different servers. In this case, both servers use the same password.

<sun-appserv-instance
	 action="create"
	 instanceport="8080"
	 instance="qa"
	 passwordfile="${passwordfile}>
 <server host="greg.oracle.com"/>
 <server host="joe.oracle.com"/>
</sun-appserv-instance>

These instances can also be removed from their respective servers:

<sun-appserv-instance
	 action="delete"
	 instance="qa"
	 passwordfile="${passwordfile}>
 <server host="greg.oracle.com"/>
 <server host="joe.oracle.com"/>
</sun-appserv-instance>

Different instance names and instance ports can also be specified using attributes of the server subelement:

<sun-appserv-instance action="create" passwordfile="${passwordfile}>
 <server host="greg.oracle.com" instanceport="8080" instance="qa"/>
 <server host="joe.oracle.com" instanceport="9090"
	 instance="integration-test"/>
</sun-appserv-instance>

The sun-appserv-component Task

Enables or disables the following Java EE component types that have been deployed to the GlassFish Server.

You do not need to specify the archive to enable or disable a component: only the component name is required. You can use the component archive, however, because it implies the component name.

Subelements of sun-appserv-component

The following table describes subelements for the sun-appserv-component task. These are objects upon which this task acts.

Table 3–7 The sun-appserv-component Subelements

Element 

Description 

The server Subelement

A GlassFish Server instance 

The component Subelement

A component to be deployed 

The fileset Subelement

A set of component files that match specified parameters 

Attributes of sun-appserv-component

The following table describes attributes for the sun-appserv-component task.

Table 3–8 The sun-appserv-component Attributes

Attribute 

Default 

Description 

action

none 

The control command for the target server instance. Valid values are enable and disable.

name

file name without extension 

(optional if a component or fileset subelement is present or the file attribute is specified, otherwise required) The display name for the component being enabled or disabled.

file

none 

(optional) The component to enable or disable. If this attribute refers to a file, it must be a valid archive. If this attribute refers to a directory, it must contain a valid archive in which all components have been exploded. 

user

admin

(optional) The user name used when logging into the GlassFish Server administration instance. This attribute is inherited by nested server elements.

passwordfile

none 

(optional) File containing passwords. The password from this file is retrieved for communication with the GlassFish Server administration instance. This attribute is inherited by nested server elements.

host

localhost

(optional) Target server. When enabling or disabling a remote server, use the fully qualified host name. This attribute is inherited by nested server elements.

port

4848

(optional) The administration port on the target server. This attribute is inherited by nested server elements.

target

name of default instance 

(optional) Target server instance. This attribute is inherited by nested server elements.

asinstalldir

see description 

(optional) The installation directory for the local GlassFish Server installation, which is used to find the administrative classes. If not specified, the command checks to see if the asinstalldir parameter has been set. Otherwise, administrative classes must be in the system classpath.

Examples of sun-appserv-component

Here is a simple example of disabling a component:

<sun-appserv-component
 action="disable"
 name="simpleapp"
 passwordfile="${passwordfile}" />

Here is a simple example of enabling a component:

<sun-appserv-component
 action="enable"
 name="simpleapp"
 passwordfile="${passwordfile}" />

Here is an equivalent script showing all the implied attributes:

<sun-appserv-component
 action="enable"
 name="simpleapp"
 user="admin"
 passwordfile="${passwordfile}"
 host="localhost"
 port="4848"
 target="${default-instance-name}"
 asinstalldir="${asinstalldir}" />

This example demonstrates disabling multiple components using the archive files (EAR and WAR, in this case) and using the component name (for an EJB component in this example).

<sun-appserv-component action="disable" passwordfile="${passwordfile}">
 <component file="${assemble}/simpleapp.ear"/>
 <component file="${assemble}/simpleservlet.war"/>
 <component name="simplebean" />
</sun-appserv-component>

Components can be enabled or disabled on multiple servers in a single task. This example shows the same three components being enabled on two different instances of the GlassFish Server. In this example, the passwords for both instances are the same.

<sun-appserv-component action="enable" passwordfile="${passwordfile}">
 <server host="greg.oracle.com"/>
 <server host="joe.oracle.com"/>
 <component file="${assemble}/simpleapp.ear"/>
 <component file="${assemble}/simpleservlet.war"/>
 <component name="simplebean" />
</sun-appserv-component>

The sun-appserv-admin Task

Enables arbitrary administrative commands and scripts to be executed on the GlassFish Server. This is useful for cases where a specific Ant task has not been developed or a set of related commands are in a single script.

Subelements of sun-appserv-admin

The following table describes subelements for the sun-appserv-admin task. These are objects upon which this task acts.

Table 3–9 The sun-appserv-admin Subelements

Element 

Description 

The server Subelement

A GlassFish Server instance 

Attributes of sun-appserv-admin

The following table describes attributes for the sun-appserv-admin task.

Table 3–10 The sun-appserv-admin Attributes

Attribute 

Default 

Description 

command

none 

(exactly one of these is required: command or explicitcommand) The command to execute. If the user, passwordfile, host, port, or target attributes are also specified, they are automatically inserted into the command before execution. If any of these options are specified in the command string, the corresponding attribute values are ignored.

explicitcommand

none 

(exactly one of these is required: command or explicitcommand) The exact command to execute. No command processing is done, and all other attributes are ignored.

user

admin

(optional) The user name used when logging into the GlassFish Server administration instance. This attribute is inherited by nested server elements.

passwordfile

none 

(optional) File containing passwords. The password from this file is retrieved for communication with the GlassFish Server administration instance. This attribute is inherited by nested server elements.

host

localhost

(optional) Target server. If it is a remote server, use the fully qualified host name. This attribute is inherited by nested server elements.

port

4848

(optional) The administration port on the target server. This attribute is inherited by nested server elements.

asinstalldir

see description 

(optional) The installation directory for the local GlassFish Server installation, which is used to find the administrative classes. If not specified, the command checks if the asinstalldir parameter has been set. Otherwise, administrative classes must be in the system classpath.

Examples of sun-appserv-admin

Here is an example of executing the create-jms-dest command:

<sun-appserv-admin command="create-jms-dest --desttype topic">

Here is an example of using explicitcommand to execute the create-jms-dest command:

<sun-appserv-admin explicitcommand="create-jms-dest --desttype topic --target server1 simpleJmsDest">

The sun-appserv-jspc Task

Precompiles JSP source code into GlassFish Server compatible Java code for initial invocation by GlassFish Server. Use this task to speed up access to JSP files or to check the syntax of JSP source code. You can feed the resulting Java code to the javac task to generate class files for the JSP files.

Attributes of sun-appserv-jspc

The following table describes attributes for the sun-appserv-jspc task.

Table 3–11 The sun-appserv-jspc Attributes

Attribute 

Default 

Description 

destdir

none 

The destination directory for the generated Java source files. 

srcdir

none 

(exactly one of these is required: srcdir or webapp) The source directory where the JSP files are located.

webapp

none 

(exactly one of these is required: srcdir or webapp) The directory containing the web application. All JSP files within the directory are recursively parsed. The base directory must have a WEB-INF subdirectory beneath it. When webapp is used, sun-appserv-jspc hands off all dependency checking to the compiler.

verbose

2

(optional) The verbosity integer to be passed to the compiler. 

classpath

none 

(optional) The classpath for running the JSP compiler. 

classpathref

none 

(optional) A reference to the JSP compiler classpath. 

uribase

/

(optional) The URI context of relative URI references in the JSP files. If this context does not exist, it is derived from the location of the JSP file relative to the declared or derived value of uriroot. Only pages translated from an explicitly declared JSP file are affected.

uriroot

see description 

(optional) The root directory of the web application, against which URI files are resolved. If this directory is not specified, the first JSP file is used to derive it: each parent directory of the first JSP file is searched for a WEB-INF directory, and the directory closest to the JSP file that has one is used. If no WEB-INF directory is found, the directory from which sun-appserv-jspc was called is used. Only pages translated from an explicitly declared JSP file (including tag libraries) are affected.

package

none 

(optional) The destination package for the generated Java classes. 

asinstalldir

see description 

(optional) The installation directory for the local GlassFish Server installation, which is used to find the administrative classes. If not specified, the command checks if the asinstalldir parameter has been set. Otherwise, administrative classes must be in the system classpath.

Example of sun-appserv-jspc

The following example uses the webapp attribute to generate Java source files from JSP files. The sun-appserv-jspc task is immediately followed by a javac task, which compiles the generated Java files into class files. The classpath value in the javac task must be all on one line with no spaces.

<sun-appserv-jspc
 destdir="${assemble.war}/generated"
 webapp="${assemble.war}"
 classpath="${assemble.war}/WEB-INF/classes"
 asinstalldir="${asinstalldir}" />
<javac
 srcdir="${assemble.war}/WEB-INF/generated"
 destdir="${assemble.war}/WEB-INF/generated"
 debug="on"
 classpath="${assemble.war}/WEB-INF/classes:${asinstalldir}/lib/
   appserv-rt.jar:${asinstalldir}/lib/appserv-ext.jar">
 <include name="**/*.java"/>
</javac>

The sun-appserv-update Task

Enables deployed web applications (EAR files) and modules (EJB JAR, RAR, and WAR files) to be updated and reloaded for fast iterative development. This task copies modified class files, XML files, and other contents of the archive files to the appropriate subdirectory of the domain-dir/applications directory, then touches the .reload file to cause dynamic reloading to occur.

This is a local task and must be executed on the same machine as the GlassFish Server.

For more information about dynamic reloading, see the Oracle GlassFish Server 3.0.1 Application Deployment Guide.

Attributes of sun-appserv-update

The following table describes attributes for the sun-appserv-update task.

Table 3–12 The sun-appserv-update Attributes

Attribute 

Default 

Description 

file

none 

The component to update, which must be a valid archive. 

domain

domain1

(optional) The domain in which the application has been previously deployed. 

Example of sun-appserv-update

The following example updates the Java EE application foo.ear, which is deployed to the default domain, domain1.

<sun-appserv-update file="foo.ear"/>

The wsgen Task

Generates JAX-WS portable artifacts used in JAX-WS web services. Reads a web service endpoint class and generates all the required artifacts for web service deployment and invocation.

Attributes of wsgen

The following table describes attributes for the wsgen task.

Table 3–13 The wsgen Attributes

Attribute 

Default 

Description 

sei

none 

Specifies the name of the service endpoint interface (SEI) class. 

destdir

current directory 

(optional) Specifies where to place the output generated classes. 

classpath

system classpath 

(optional) Specifies where to find the input class files. Same as cp attribute.

cp

system classpath 

(optional) Specifies where to find the input class files. Same as classpath attribute.

resourcedestdir

current directory 

(optional) Specifies where to place generated resource files such as WSDL files. Used only if the genwsdl attribute is set to true.

sourcedestdir

current directory 

(optional) Specifies where to place generated source files. 

keep

false

(optional) If true, keeps generated files.

verbose

false

(optional) If true, outputs compiler messages.

genwsdl

true

(optional) If true, generates a WSDL file.

protocol

soap1.1

(optional) Specifies the protocol to use in the wsdl:binding. Used only if the genwsdl attribute is set to true.

Allowed values are soap1.1 or Xsoap1.2. Xsoap1.2 is not standard and is only used if the extension attribute is set to true.

servicename

none 

(optional) Specifies a particular wsdl:service name for the generated WSDL file. Used only if the genwsdl attribute is set to true. For example:

servicename="{http://mynamespace/}MyService"

portname

none 

(optional) Specifies a particular wsdl:port name for the generated WSDL. Used only if the genwsdl attribute is set to true. For example:

portname="{http://mynamespace/}MyPort"

extension

false

(optional) If true, allows vendor extensions not in the specification. Use of extensions may result in applications that are not portable and may not interoperate with other implementations.

Example of wsgen

The following example generates portable artifacts for fromjava.server.AddNumbersImpl, uses compile.classpath as the classpath, and writes the WSDL file to ${wsdl.dir}.

<wsgen
   resourcedestdir="${wsdl.dir}"
   sei="fromjava.server.AddNumbersImpl">
   <classpath refid="compile.classpath"/>
</wsgen>

The wsimport Task

Generates JAX-WS portable artifacts for a given WSDL file. Portable artifacts include service endpoint interfaces (SEIs), services, exception classes mapped from the wsdl:fault and soap:headerfault tags, asynchronous response beans derived from the wsdl:message tag, and JAXB generated value types. After generation, these artifacts can be packaged in a WAR file with the WSDL and schema documents along with the endpoint implementation and then deployed.

Attributes of wsimport

The following table describes attributes for the wsimport task.

Table 3–14 The wsimport Attributes

Attribute 

Default 

Description 

wsdl

none 

Specifies the name of the WSDL file. 

destdir

current directory 

(optional) Specifies where to place the output generated classes. 

sourcedestdir

current directory 

(optional) Specifies where to place generated source files. Used only if the keep attribute is set to true.

keep

false

(optional) If true, keeps generated files.

verbose

false

(optional) If true, outputs compiler messages.

binding

none 

(optional) Specifies external JAX-WS or JAXB binding files. JAX-WS and JAXB binding files can customize things like package names and bean names. More information on JAX-WS and JAXB binding files can be found in the customization documentation included with this release. 

extension

false

(optional) If true, allows vendor extensions not in the specification. Use of extensions may result in applications that are not portable and may not interoperate with other implementations.

wsdllocation

none 

(optional) Specifies the value of @WebService.wsdlLocation and @WebServiceClient.wsdlLocation annotation elements for the generated SEI and Service interface. This should be set to the URI of the web service WSDL file.

catalog

none 

(optional) Specifies the catalog file to resolve external entity references. Supported formats are TR9401, XCatalog, and OASIS XML Catalog. Additionally, the Ant xmlcatalog type can be used to resolve entities.

package

none 

(optional) Specifies the target package, overriding any WSDL and schema binding customization for package name, and the default package name algorithm defined in the JAX-WS specification. 

Example of wsimport

The following example generates client-side artifacts for AddNumbers.wsdl and stores .class files in the ${build.classes.home} directory using the custom.xml customization file.

<wsimport
   destdir="${build.classes.home}"
   wsdl="AddNumbers.wsdl"
   binding="custom.xml">
</wsimport>

Reusable Subelements

Reusable subelements of the Ant tasks for the GlassFish Server are as follows. These are objects upon which the Ant tasks act.

The server Subelement

Specifies a GlassFish Server instance. Allows a single task to act on multiple server instances. The server attributes override corresponding attributes in the parent task; therefore, the parent task attributes function as default values.

Attributes of server

The following table describes attributes for the server element.

Table 3–15 The server Attributes

Attribute 

Default 

Description 

user

admin

(optional) The user name used when logging into the GlassFish Server domain administration server (DAS). 

passwordfile

none 

(optional) File containing passwords. The password from this file is retrieved for communication with the GlassFish Server DAS. 

host

localhost

(optional) Target server. When targeting a remote server, use the fully qualified host name. 

port

4848

(optional) The administration port on the target server. 

instance

name of default instance 

(optional) Target server instance. 

instanceport

none 

(applies to The sun-appserv-instance Task only) Deprecated.

debug

false

(applies to The sun-appserv-instance Task only, optional) Deprecated. If action is set to start, specifies whether the server starts in debug mode. This attribute is ignored for other values of action. If true, the instance generates additional debugging output throughout its lifetime.

upload

true

(applies to The sun-appserv-deploy Task only, optional) If true, the component is transferred to the server for deployment. If the component is being deployed on the local machine, set upload to false to reduce deployment time.

virtualservers

default virtual server only 

(applies to The sun-appserv-deploy Task only, optional) A comma-separated list of virtual servers to be deployment targets. This attribute applies only to application (.ear) or web (.war) components and is ignored for other component types.

Examples of server

You can control multiple servers using a single task. In this example, two servers are started, each using a different password. Only the second server is started in debug mode.

<sun-appserv-instance action="start">
<server host="greg.oracle.com" passwordfile="${password.greg}"/>
<server host="joe.oracle.com" passwordfile="${password.joe}"
	 debug="true"/>
</sun-appserv-instance>

You can create instances on multiple servers using a single task. This example creates a new instance named qa on two different servers. Both servers use the same password.

<sun-appserv-instance action="create" instanceport="8080"
	 instance="qa" passwordfile="${passwordfile}>
<server host="greg.oracle.com"/>
<server host="joe.oracle.com"/>
</sun-appserv-instance>

These instances can also be removed from their respective servers:

<sun-appserv-instance action="delete" instance="qa"
	 passwordfile="${passwordfile}>
<server host="greg.oracle.com"/>
<server host="joe.oracle.com"/>
</sun-appserv-instance>

You can specify different instance names and instance ports using attributes of the nested server element:

<sun-appserv-instance action="create" passwordfile="${passwordfile}>
<server host="greg.oracle.com" instanceport="8080" instance="qa"/>
<server host="joe.oracle.com" instanceport="9090"
	instance="integration-test"/>
</sun-appserv-instance>

You can deploy multiple components to multiple servers (see the The component Subelement) . This example deploys each component to two GlassFish Server instances running on remote servers. Both servers use the same password.

<sun-appserv-deploy passwordfile="${passwordfile}" 
  asinstalldir="/opt/s1as8" >
<server host="greg.oracle.com"/>
<server host="joe.oracle.com"/>
<component file="${assemble}/simpleapp.ear"/>
<component file="${assemble}/simpleservlet.war"
	 contextroot="test"/>
<component file="${assemble}/simplebean.jar"/>
</sun-appserv-deploy>

You can also undeploy multiple components from multiple servers. This example shows the same three components being removed from two different instances. Both servers use the same password.

<sun-appserv-undeploy passwordfile="${passwordfile}">
<server host="greg.oracle.com"/>
<server host="joe.oracle.com"/>
<component file="${assemble}/simpleapp.ear"/>
<component file="${assemble}/simpleservlet.war"/>
<component name="simplebean" />
</sun-appserv-undeploy>

You can enable or disable components on multiple servers. This example shows the same three components being enabled on two different instances. Both servers use the same password.

<sun-appserv-component action="enable" passwordfile="${passwordfile}">
<server host="greg.oracle.com"/>
<server host="joe.oracle.com"/>
<component file="${assemble}/simpleapp.ear"/>
<component file="${assemble}/simpleservlet.war"/>
<component name="simplebean" />
</sun-appserv-component>

The component Subelement

Specifies a Java EE component. Allows a single task to act on multiple components. The component attributes override corresponding attributes in the parent task; therefore, the parent task attributes function as default values.

Attributes of component

The following table describes attributes for the component element.

Table 3–16 The component Attributes

Attribute 

Default 

Description 

file

none 

(optional if the parent task is The sun-appserv-undeploy Task or The sun-appserv-component Task) The target component. If this attribute refers to a file, it must be a valid archive. If this attribute refers to a directory, it must contain a valid archive in which all components have been exploded. If upload is set to false, this must be an absolute path on the server machine.

name

file name without extension 

(optional) The display name for the component. 

force

true

(applies to The sun-appserv-deploy Task only, optional) If true, the component is overwritten if it already exists on the server. If false, the containing element’s operation fails if the component exists.

precompilejsp

false

(applies to The sun-appserv-deploy Task only, optional) If true, all JSP files found in an enterprise application (.ear) or web application (.war) are precompiled. This attribute is ignored for other component types.

retrievestubs

client stubs not saved 

(applies to The sun-appserv-deploy Task only, optional) The directory where client stubs are saved.

contextroot

file name without extension 

(applies to The sun-appserv-deploy Task only, optional) The context root for a web module (WAR file). This attribute is ignored if the component is not a WAR file.

verify

false

(applies to The sun-appserv-deploy Task only, optional) If true, syntax and semantics for all deployment descriptors is automatically verified for correctness.

Examples of component

You can deploy multiple components using a single task. This example deploys each component to the same GlassFish Server instance running on a remote server.

<sun-appserv-deploy passwordfile="${passwordfile}" host="greg.oracle.com"
	 asinstalldir="/opt/s1as8" >
<component file="${assemble}/simpleapp.ear"/>
<component file="${assemble}/simpleservlet.war"
	 contextroot="test"/>
<component file="${assemble}/simplebean.jar"/>
</sun-appserv-deploy>

You can also undeploy multiple components using a single task. This example demonstrates using the archive files (EAR and WAR, in this case) and the component name (for the EJB component).

<sun-appserv-undeploy passwordfile="${passwordfile}">
<component file="${assemble}/simpleapp.ear"/
<component file="${assemble}/simpleservlet.war"/>
<component name="simplebean" />
</sun-appserv-undeploy>

You can deploy multiple components to multiple servers. This example deploys each component to two instances running on remote servers. Both servers use the same password.

<sun-appserv-deploy passwordfile="${passwordfile}" asinstalldir="/opt/s1as8" >
<server host="greg.oracle.com"/>
<server host="joe.oracle.com"/>
<component file="${assemble}/simpleapp.ear"/>
<component file="${assemble}/simpleservlet.war"
	contextroot="test"/>
<component file="${assemble}/simplebean.jar"/>
</sun-appserv-deploy>

You can also undeploy multiple components to multiple servers. This example shows the same three components being removed from two different instances. Both servers use the same password.

<sun-appserv-undeploy passwordfile="${passwordfile}">
<server host="greg.oracle.com"/>
<server host="joe.oracle.com"/>
<component file="${assemble}/simpleapp.ear"/>
<component file="${assemble}/simpleservlet.war"/>
<component name="simplebean" />
</sun-appserv-undeploy>

You can enable or disable multiple components. This example demonstrates disabling multiple components using the archive files (EAR and WAR, in this case) and the component name (for the EJB component).

<sun-appserv-component action="disable" passwordfile="${passwordfile}">
<component file="${assemble}/simpleapp.ear"/>
<component file="${assemble}/simpleservlet.war"/>
<component name="simplebean" />
</sun-appserv-component>

You can enable or disable multiple components on multiple servers. This example shows the same three components being enabled on two different instances. Both servers use the same password.

<sun-appserv-component action="enable" passwordfile="${passwordfile}">
<server host="greg.oracle.com"/>
<server host="joe.oracle.com"/>
<component file="${assemble}/simpleapp.ear"/>
<component file="${assemble}/simpleservlet.war"/>
<component name="simplebean" />
</sun-appserv-component>

The fileset Subelement

Selects component files that match specified parameters. When fileset is included as a subelement, the name and contextroot attributes of the containing element must use their default values for each file in the fileset. For more information, see http://ant.apache.org/manual/Types/fileset.html.