Section 3.1. Building and Deploying the Ajax Application


3.1. Building and Deploying the Ajax Application

We now have all the components required to build the example. If you have never used Ant, you are about to be surprised by a powerful tool.

An Ant tutorial is beyond the scope of this book. If you don't understand the build.xml file in this section, you should refer to the Ant documentation at http://ant.apache.org.


The build.xml file presented in Example 3-3 builds the project and moves it to the tomcat/webapps directory; that's all Tomcat needs in order to begin running the web application. Make sure you have set TOMCAT_HOME to the directory where you installed Tomcat. Refer back to Chapter 1 for setup details.

Example 3-3. build.xml

 <?xml version="1.0"?> <project name="CH03 AJAX-CODECONVERTER" default="compile" basedir=".">     <property environment="env"/>     <property name="src.dir" value="src"/>     <property name="war.dir" value="war"/>     <property name="class.dir" value="${war.dir}/WEB-INF/classes"/>     <property name="lib.dir" value="${war.dir}/WEB-INF/lib"/>     <property name="webapp.dir"               value="${env.TOMCAT_HOME}/webapps/ch03-ajaxcharacterconverter"/>     <path >         <fileset dir="${lib.dir}">             <include name="*.jar"/>         </fileset>     </path>     <target name="init">         <mkdir dir="${class.dir}"/>     </target>     <target name="compile" depends="init"             description="Compiles all source code.">         <javac srcdir="${src.dir}" destdir="${class.dir}" debug="on"                classpathref="ajax.class.path"/>     </target>     <target name="clean" description="Erases contents of classes dir">         <delete dir="${class.dir}"/>     </target>     <target name="deploy" depends="compile"             description="Copies the contents of web-app to destination dir">         <copy todir="${webapp.dir}">             <fileset dir="${war.dir}"/>         </copy>     </target> </project> 

When you've created the build.xml file, you should be able to build and deploy the project with the following command:

 ant deploy 

3.1.1. Directory Structure

For the build to work correctly, you must have the directory structure just right. Figure 3-1 shows the directory structure that I use with Eclipse. It can be modified, but build.xml should reflect the directory structure you are using.

Figure 3-1. Directory structure for Ajax Character Decoder (first version)





Ajax on Java
Ajax on Java
ISBN: 0596101872
EAN: 2147483647
Year: 2007
Pages: 78

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net