|
Home
TOC Index |
|
Building the Getting Started Application Using Ant
Now the example Web application is ready to build.
This release of the Java Web Services Developer Pack includes
Ant, a make tool that is portable across platforms, and which is developed by the Apache Software Foundation (http://www.apache.org). Documentation for theAnttool can be found in the fileindex.htmlfrom the <JWSDP_HOME>/docs/ant/directory of your Java WSDP installation.
Note: It is critical that yourPATHvariable includes thePATHto thebindirectory of the Java WSDP at the front of thePATH. If not, many of theAntcommands will not work because the version ofAntshipped with the Java WSDP sets thejwsdp.homeenvironment variable and other versions ofAntwill not.
This example uses the
Anttool to manage the compilation of our Java source code files and creation of the deployment hierarchy.Antoperates under the control of a build file, normally calledbuild.xml, that defines the processing steps required. This file is stored in the top-level directory of your source code hierarchy.Like a
Makefile, thebuild.xmlfile provides several targets that support optional development activities (such as erasing the deployment home directory so you can build your project from scratch). This build file includes targets for compiling the application, installing the application on a running server, reloading the modified application onto the running server, and removing old copies of the application to regenerate their content.When we use the
build.xmlfile in this example application to compile the source files, a temporary/builddirectory is created beneath the root. This directory contains an exact image of the binary distribution for your Web application. This directory is deleted and recreated as needed during development, so don't edit the files in this directory.Creating the Build and Deploy File for Ant
To use
Antfor this example, create the filebuild.xmlin thegs/directory. The code for this file follows:><!-- Setting up the Getting Started example to prepare to build and deploy --> <project name="gs-example" default="build" basedir="."> <target name="init"> <tstamp/> </target> <!-- Configure the context PATH for this application --> <property name="example" value="GSApp" /> <property name="path" value="/${example}"/> <property name="build" value="${jwsdp.home}/docs/tutorial/examples/${example}/build" /> <!-- Configure properties to access the Manager application -- > <property name="url" value="http://localhost:8080/manager"/> <property file="build.properties"/> <property file="${user.home}/build.properties"/> <!-- Configure custom Ant tasks for the Manager application --> <path id="classpath"> <fileset dir="${jwsdp.home}/common/lib"> <include name="*.jar"/> </fileset> </path> <taskdef name="install" classname="org.apache.catalina.ant.InstallTask" /> <taskdef name="reload" classname="org.apache.catalina.ant.ReloadTask" /> <taskdef name="remove" classname="org.apache.catalina.ant.RemoveTask"/> <target name="prepare" depends="init" description="Create build directories."> <mkdir dir="${build}" /> <mkdir dir="${build}/WEB-INF" /> <mkdir dir="${build}/WEB-INF/classes" /> </target> <!-- Executable Targets --> <target name="install" description="Install Web application" depends="build"> <install url="${url}" username="${username}" password="${password}" path="${path}" war="file:${build}"/> </target> <target name="reload" description="Reload Web application" depends="build"> <reload url="${url}" username="${username}" password="${password}" path="${path}"/> </target> <target name="remove" description="Remove Web application"> <remove url="${url}" username="${username}" password="${password}" path="${path}"/> </target> <target name="build" depends="prepare" description="Compile app Java files and copy HTML and JSP pages" > <javac srcdir="src" destdir="${build}/WEB-INF/classes"> <include name="**/*.java" /> <classpath refid="classpath"/> </javac> <copy todir="${build}/WEB-INF"> <fileset dir="web/WEB-INF" > <include name="web.xml" /> </fileset> </copy> <copy todir="${build}"> <fileset dir="web"> <include name="*.html"/> <include name="*.jsp" /> <include name="*.gif" /> </fileset> </copy> </target> </project>Compiling the Source Files
To compile the JavaBeans component (
ConverterBean.java), we will use theAnttool and run thebuildtarget in thebuild.xmlfile. The steps for doing this follow.
- In a terminal window, go to the
gs/directory if you are creating the application on your own, or go to the <JWSDP_HOME>/docs/tutorial/examples/gs/directory if you are compiling the example files downloaded with the tutorial.- Type the following command to build the Java files:
ant build
- This command compiles the source files for the
ConverterBean. It places the resulting class files in the<JWSDP_HOME>/docs/tutorial/examples/GSApp/build/WEB-INF/classes/converterAppdirectory as specified in thebuildtarget inbuild.xml. It also places theindex.jspfile in theGSApp/builddirectory and places theweb.xmlfile in theGSApp/build/WEB-INFdirectory. Tomcat allows you to deploy an application in an unpacked directory like this. Deploying the application is discussed in Deploying the Application.
|
Home
TOC Index |
|
This tutorial contains information on the 1.0 version of the Java Web Services Developer Pack.
All of the material in The Java Web Services Tutorial is copyright-protected and may not be published in other works without express written permission from Sun Microsystems.