Sun Java System Application Server 

Samples Index

Using Ant with Sample Applications

Sun Java System Application Server includes a Java-based build tool called Ant, developed by the Apache Software Foundation.

Benefits Of Using Ant

Many server side Java developers have found Ant to useful for accelerating development of J2EE applications. Ant contains many built-in functions that relieve the burden of repetitive development tasks. As described in the Ant documentation, "In theory it is like make without make's wrinkles".

For more information about Ant, see the Apache Ant Project.

Ant Environment in Application Server

In the Ant environment, build.xml files are analogous to Makefiles. A build.xml file can define various targets that are used to compile and assemble a J2EE application. To use Ant with the sample applications provided as part of the application server, you need to ensure that your PATH includes the install_dir/bin directory of your application server installation. A simple wrapper script named asant(.bat) is located in this directory. No further set up is required.

The following build targets are represented in the build.xml files accompanying the sample applications. The presence or absence of a target depends on the type of J2EE application.

Standard Ant Build Targets
Target Function
compile Compiles all Java source code.
war Assembles the WAR file in sample_dir/build/assemble/war/
ear Assembles the EAR file insample_dir/build/assemble/ear/
core (default) Compiles all sources, builds stubs/skeletons and assembles EJB[tm] JAR, WAR and EAR files. This is the default target for all build.xml files shipped in the application server.
docs Creates Java docs in <sample_dir>/javadocs
all Builds both core and javadocs, verifies, registers resources and deploys app.
deploy Registers resources, deploys app, but does not install Javadocs.
deploy_common Application deployment only. No resource registration.
verify Verifies application binaries.
undeploy Removes the deployed sample from application server.
clean Removes appname/build/ content.

Using the Build Facility

Follow these steps to use Ant for the first time:

  1. Set Up Your Environment

    The install_dir/bin directory must be in your PATH environment variable.

    On UNIX platforms, you will need to add theinstall_dir/bin directory to your PATH environment variable.

    On Windows platforms, after installation of the application server, set the System path by adding install_dir\bin to your user PATH environment variable.

  2. Configure the Properties File

    To deploy sample applications, you must set property values in the install_dir/samples/common.properties file to the appropriate values for your environment. If a property contained in this file is not set, you will be prompted for the property's value during the deployment of a sample application.

    See Creating Your Own Samples Environment section for a description of the common.properties file.

  3. Compile and Assemble a Sample Application

    Using the blueprints/petstore1.4 sample as an example, execute several of the build targets.

    Change to the blueprints/petstore1.4/src directory:

    cd install_dir/samples/blueprints/petstore1.4/src

    Execute the compile target to compile the Java sources:

    asant core

    This target assembles the J2EE module files and the EAR files.

    Alternatively, you could accomplish all of these tasks by simply executing either the core or all targets:

    asant all

    Since the default build target is core, you could execute ant without arguments to rebuild the entire application:

    asant
  4. Build Additional Examples
  5. The following examples demonstrate how to use the build facility to quickly accomplish common development and deployment tasks:

    • Build everything (including Javadocs). Then install Javadocs and deploy the application:
      asant all
    • Build everything (except for Javadocs). Then deploy the application (most frequently used approach):
      asant core
      asant deploy 
    • Rebuild an EAR After modifying the deployment descriptors (no recompile needed):
      asant ear
      asant deploy_common

Redeploying Applications : To redeploy an application, use the deploy_common target. Execution of this target will not result in an attempt to register the necessary resources. If you attempt to execute the deploy target several times in succession, then the subsequent deployment attempts may fail because the resources will have already been registered.


Custom Ant Tasks

The Application Server comes with custom Ant tasks that are part of the build environment for all samples. The following tasks are used in the sample build.xml files:

Custom Ant Task Function
sun-appserv-deploy
Deploys J2EE components to the Application Server.
sun-appserv-undeploy Undeploys J2EE components from the Application Server.
sun-appserv-admin Enables arbitrary administrative commands and scripts to be executed on the Application Server.

For more information about these Ant tasks and for a full list of the custom Ant tasks, please see the Administrator's Guide on docs.sun.com.

Using Sample Build Files in Netbeans 4.1

Netbeans 4.1 includes support for Ant build files. To use the IDE to execute the targets contained in the sample application build.xml files, you must add the JAR file containing the custom Ant tasks for Application Server to the IDE's classpath. Follow this procedure:

  1. Copy the file install_dir/lib/sun-appserv-ant.jar from the application server's installation directory to the ide_install_dir/ide5/ant/patches/org-apache-tools-ant-module/ directory and restart the IDE.
  2. Mount a file system in the IDE that corresponds to a top level directory of a sample application. For example, samples_dir/quickstart
  3. Expand the build node under the quickstart/ directory to list the targets available in the sample's build.xml file.
  4. Double click the compile target to recompile the sample application.
  5. Execute additional targets to experiment with other operations such as deployment and undeployment of applications.

      To deploy a sample application, ensure that you modify the samples/common.properties andf set the admin.password to the appropriate value.


      Copyright © 2006 Sun Microsystems, Inc. All rights reserved.