The JavaTM Web Services Tutorial
Home
TOC
PREV TOP NEXT

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 the Ant tool can be found in the file index.html from the <JWSDP_HOME>/docs/ant/ directory of your Java WSDP installation.

This example uses the Ant tool to manage the compilation of our Java source code files and creation of the deployment hierarchy. Ant operates under the control of a build file, normally called build.xml, that defines the processing steps required. This file is stored in the top-level directory of your source code hierarchy.

Like a Makefile, the build.xml file 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.xml file in this example application to compile the source files, a temporary /build directory 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 Ant for this example, create the file build.xml in the gs/ 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="gs" /> 	
<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 the Ant tool and run the build target in the build.xml file. The steps for doing this follow.

  1. 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.
  2. 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 gs/build/WEB-INF/classes/src/converterApp directory as specified in the build target in build.xml. It also places the index.jsp file in the gs/build directory. Tomcat allows you to deploy an application in an unpacked directory like this. Deploying the application is discussed in Deploying the Application.

Home
TOC
PREV TOP NEXT