Building Web Applications  

This document describes how to build web applications using the sample Ant file buildapps.xml. You can find this file in the <JAVA-HOME>/docs directory. (See the bullet item under conventions used, in the next section, for an explanation of <JAVA-HOME>.) The great advantage in using an Ant build file is that it is cross-platform.

Overview

The file buildapps.xml is an Ant file that you invoke by calling the command ant. This particular Ant file is designed to be used when you want your application to be able to run in a container such as Tomcat or in a JavaTM 2 Platform, Enterprise Edition (J2EETM) container. For a standalone application, you do not need to use this build file.

The file buildapps.xml constructs a directory structure in which you can write your application, so you call it before you write your code. When you have finished your application, you call it again to create a .war (Web Archive) file.

Conventions used in this document:

Setting Up

  1. Create a directory with the name of the application you will write.
    Let's assume that the name of this directory is jaxmapp.
    	  cd $JAXM_HOME
    	  mkdir jaxmapp
      
  2. Create a WEB-INF directory under jaxmapp.
    	  cd jaxmapp
    	  mkdir WEB-INF
      
  3. Copy the buildapps.xml file into the WEB-INF directory, changing its name to build.xml.
    	  cd WEB-INF
    	  cp $JAXM_HOME/docs/buildapps.xml build.xml
      
    When you call the ant command, it will look for this build.xml file.

  4. Create the file build.properties in the WEB-INF directory and give it the specified name/value pairs. The following shows what your file might look like for Unix. You will need to make the appropriate changes for Windows.
    The following conventions are used: You must write out the full path name because environment variables will not be handled properly.
          jaxm.home=/home/happy/installs/JAXPACK/JAXMDIR
          servlet.jar=/home/happy/installs/jakarta-tomcat-4.0/common/lib/servlet.jar
          webapps.dir=/home/happy/installs/jakarta-tomcat-4.0/webapps
          appname=jaxmapp
          appdir=/home/happy/installs/JAXPACK/JAXMDIR/jaxmapp
          wars.dir=/home/happy/installs/jakarta-tomcat-4.0/webapps
      
    Note that the information in the build.properties file can be supplied at the command line, but it is generally more convenient to use a properties file. For example, supplying the appname property at the command line would look like this:
    		ant -Dappdir="jaxmapp"
       

    Running Ant

    Given the setup just created, you call the ant command as follows. If you have not already added $JAXM_HOME/bin to your PATH, you should do so now. We recommend putting it at the beginning of your PATH to be sure you get the right version if you have downloaded a JavaTM XML Pack release previously.
        cd $JAXM_HOME/jaxmapp/WEB-INF
        ant
    
    The result of this call is the creation of several directories in the Tomcat directory structure.

    Directory Structure

    NOTE: <TOMCAT_HOME> is the directory where you unpacked your download of the Tomcat server.
    Running this ant command creates the directory jaxmapp in <TOMCAT_HOME>/webapps and the directory WEB-INF as a subdirectory under jaxmapp. So, you will now have the following:
        $TOMCAT_HOME/webapps/jaxmapp/WEB-INF
    
    The WEB-INF directory contains the following subdirectories:
         classes
         lib
         src
    
    Now you need to populate this directory structure by doing the following:

    Creating the War File

    After you have put the appropriate files in this directory structure, you can create the .war file for your application with the same ant command you used before except with "war" appended to it. It will look like this:
        cd $JAXM_HOME/jaxmapp/WEB-INF
        ant war
    
    This will create the file jaxmapp.war in the $TOMCAT_HOME/webapps directory.