Building Web Applications  

This document describes how to build web applications using the sample Ant file buildapps.xml. You can find this file at <JWSDP-HOME>/docs/jaxm/buildapps.xml.

Overview

The file buildapps.xml is an Ant file that you invoke by calling the command ant. You use this build file 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:

  1. JWSDP_HOME designates the directory where you unpacked this release of the JavaTM Web Services Developer Pack. This document uses the Unix form $JWSDP_HOME; for Windows, use %JWSDP_HOME%.

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 $JWSDP_HOME/work
    	  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 $JWSDP_HOME/docs/jaxm/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. /home/happy/installs/JWSDP is the directory that contains Tomcat. You must write out the full path name because environment variables will not be handled properly.
          servlet.jar=/home/happy/installs/JWSDP/common/lib/servlet.jar
          webapps.dir=/home/happy/installs/JWSDP/webapps
          appname=jaxmapp
          appdir=/home/happy/installs/JWSDP/work/jaxmapp
          wars.dir=/home/happy/installs/JWSDP/webapps
          jaxm.home=/home/happy/installs/JWSDP
      
    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.

    Running Ant

    Given the setup just created, you call the ant command as follows. If you have not already added $JWSDP_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 $JWSDP_HOME/work/jaxmapp/WEB-INF
        ant
    
    The result of this call is the creation of several directories in the Tomcat directory structure.

    Directory Structure

    NOTE: $JWSDP_HOME is the directory where you have Tomcat 4.
    Running this command creates the directory jaxmapp in $JWSDP_HOME/webappsand the directory WEB-INF as a subdirectory under jaxmapp. So, you will now have the following:
        $JWSDP_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 $JWSDP_HOME/work/jaxmapp/WEB-INF
        ant war
    
    This will create the file jaxmapp.war in the $JWSDP_HOME/webapps directory.