This product includes
software developed by the Apache Software Foundation (http://www.apache.org).
Specifically, the Ant Java[tm]-based build tool is included as part of
Sun Java (tm) System Application Server.
Benefits
Of Using Ant
Many server side Java developers
have found Ant to be an extremely useful tool for accelerating the development
cycle associated with J2EE[tm] 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 kind of like make without make's
wrinkles". For more information about Ant, see:
http://jakarta.apache.org/ant/index.html
Ant Environment
in Sun Java (tm) System Application Server 7
In the Ant environment, build.xml
files are analogous to a 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
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. Since the Java Pet Store
application from Sun Microsystems already includes build.xml
files, you might notice that not all of the following targets are represented
in the Java Pet Store sample application bundled with the application server.
Target |
Function |
compile |
Compiles all Java source code. |
war |
Assembles the WAR file in
<sample_dir>/assemble/war/. |
ear |
Assembles the EAR file in
<sample_dir>/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. |
javadocs |
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. |
undeploy |
Removes the deployed sample from application server. |
clean |
Removes <appname>/build/
and <appname>/assemble/ content. |
verify |
Executes the J2EE application verifier against the sample
application. |
Using
the Build Facility
1. Set Up Your Environment
In order to use the Ant tool
to compile and reassemble the sample applications, you need to ensure that
the <install_dir>/bin
directory is in your environment's
path (PATH environment variable).
2. Compile and Assemble
a Sample Application
Using the simple stateless
EJB sample as an example, execute several of the build targets.
Change to the ejb/stateless/simple
sample
directory:
cd <install_dir>/samples/ejb/stateless/simple/src
Execute the compile target to
compile the Java sources:
asant compile
Execute the ear target
to assemble the J2EE module files (war and jar) into the EAR file:
asant ear
The ear target's calling war and jar targets for this sample.
Alternatively, you could accomplish
all these tasks (compile and ear targets) by simply executing either the
core
or all
targets:
asant core
Since the default build target
is core,
you could execute ant without arguments to rebuild the entire application:
asant
3. Additional Build Examples
The following examples demonstrate
how one can use the build facility to quickly accomplish recurring development
and deployment tasks.
Build everything including
Javadocs and deploy the application:
asant all
Build everything (except for
Javadocs) and then deploy the application (most frequently used approach):
asant core
(or simply: asant)
asant deploy
Rebuild an EAR After modifying
the deployment descriptors (no recompile needed):
asant ear
asant deploy_common
Redeploying
Applications : To redeploy an application, it is recommended that you
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. |
common.properties
File: In order to deploy
sample applications, property settings in the common.properties
file under <install_dir>/samples/
must be set 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 the Creating Your Own Samples Environment
section for a detailed description of the properties contained in the common.properties
file. |
Custom
Ant Tasks
The Sun Java (tm) System Application Server
7 ships 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
modules to the Sun Java (tm) System Application Server 7. |
sun-appserv-undeploy |
Undeploys J2EE
components from the Sun Java (tm) System Application Server 7. |
sun-appserv-admin |
Enables arbitrary
administrative commands and scripts to be executed on the Sun Java (tm) System Application
Server 7. |
For more information about
these Ant tasks and for a full list of the custom Ant tasks, please see
the Sun Java (tm) System Application Server Developer's Guide documentation.
Using Sample
Build Files in Sun ONE Studio 4
The Sun ONE Studio 4, Enterprise
Edition for Java IDE includes support for Ant build files. To use the IDE
to execute the targets contained in the sample application build.xml
files, you must ensure that the the JAR file containing the custom Ant
tasks for Sun Java (tm) System Application Server 7 is added to the IDE's classpath.
1. Copy the file <install_dir>/lib/sun-appserv-ant.jar
from
the application server's installation directory to the <ide_install_dir>/modules/patches/org-apache-tools-ant-module/
directory and restart the IDE.
2. Mount a file system in the IDE that corresponds to a src/
directory
of a sample application. For example:
<samples_dir>/jdbc/simple/src
3. Expand the build node
under the src/ 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.
In order to deploy a sample application, ensure that you modify thesamples/common.properties
file by setting the admin.password to the appropriate value. |