Building and Deploying Struts Applications Using Jakarta Ant


You might have been using Ant all through the book. At least a few previous chapters came with Ant build files. But we felt it was important to dedicate some space to Ant directly because of its importance and because many readers probably haven't used it to a great extent.

In this section, you revisit the original Hello World application from back in Chapter 3. It's a simple, basic application and is just right for demonstrating the process of creating an Ant build file.

To begin with, you need two directory structures. The first is the development structure where the files are kept while you're working on them. The second directory structure is the one you have to deploy the application into after you compile your code. Both are described in the next sections.

A Recommended Directory Structure for Development

How you structure your files during development is many times a personal thing. But after you standardize on a build process, everyone has to do things the same way for the build files to work. There are many different ways you could store your files during development, and each of them has its own benefits and drawbacks. The directory structure used in this chapter is

 app.home --+                   - Top level directory                          +-- build          - Top of build/assemble area                          +-- deploy         - Generate the WAR file into here                          +-- doc            - Javadoc is generated below here                          +-- lib            - Store all JARs and so on here                          +-- object         - Holds compiled .class files                          +-- src            - Java source top directory                          +-- web            - Top of your JSP directory                                      +--WEB-INF   - web.xml, struts-config.xml, tld 

Here's a list of what each is used for and what generally goes in each directory:

  • app.home ” The top of the development directory tree. For this application, the only files in this directory are the build.xml file (the default Ant build file) and the build.properties file (which contains properties that are specific to this particular host). We'll talk more about these files later.

  • build ” This directory is the place you build the WAR file in preparing it for deployment. Beneath it is built a direct image of what must go in the WAR file (which is discussed in more detail in the next section). Between builds, this entire directory may be deleted and rebuilt from scratch.

  • deploy ” This directory contains nothing except those files that will be physically deployed to the server to be run. For this application, this is a single file: strutsANT.war .

  • doc ” This file contains the Javadoc for the application when it's generated. Other project documentation may optionally be maintained in this directory.

  • lib ” This directory holds all the .jar files and other library files. All these files are later copied into the build directory for inclusion in the strutsANT.war file.

  • src ” This is the top of the source directory where all your source code goes. We recommend that you manage check-in/ check-out to and from source control from within this directory. In addition to all Java source files, any other files that must be placed somewhere on the classpath (for example, .properties files) should be placed here as well.

  • web ” The top of your Web application ( .jsp files, images, and so on) directory.

  • WEB-INF ” The web.xml , struts-config.xml , and all Struts and other JSP custom tag library files ( tld files) reside here.

The following section discusses the structure of the Web application that the build process must create.

The Required Directory Structure for the Deployed Application (and .war File)

The structure of a Web application (Web app) is governed by the Java Servlet specifications (which can be reviewed via the Java Community Process site at http://www.jcp.org/jsr/detail/53.jsp).

The directory structure required for a Web app is

 / --+                      - Web app (JSP) root directory                      +-- META-INF          - Holds the Manifest.mf file                      +-- WEB-INF           - web.xml, struts-config.xml, tld                                      +-- lib       - Store all jars, etc here                                      +-- classes   - Holds compiled .class files 

Here's a list of what each is used for and what generally goes in each directory:

  • / ” The top of the Web app directory tree. If you have an index.jsp file, it goes here. You'll generally have subdirectories below here for other .jsp files, images, and so on.

  • META-INF ” This directory holds the manifest file, Manifest.mf . The manifest file is generated automatically by Ant.

  • WEB-INF ” This directory holds the web.xml file, which is the deployment descriptor for the Web app itself. It also holds all TLD files for the Struts and other tag libraries as well as the struts-config.xml configuration file.

  • lib ” This holds library files ( .jar files) that are specific to this particular application.

  • classes ” This is the top-level directory for all your compiled .class files. As mentioned previously, any of your applications .properties or other files that must be on your classpath must go in this directory structure as well.

This directory structure (except for the META-INF directory, which is created by the ant <war> task) is created in your development area (in the build section) by the Ant build script, and then compressed into the Web archive ( .war ) file for deployment.

WORKING WITH .WAR FILES

When working with .war files, it's useful to know that they can be treated like .jar files with a different file extension.

To view the contents of a .war file, you can use the jar utility. For example, the command

 jar tvf strutsANT.war 

displays the contents of the strutsANT.war file.

Alternatively, you can open , view, and update .war files using the WinZip compression utility. Simply open them as you would any .zip file.



Struts Kick Start
Struts Kick Start
ISBN: 0672324725
EAN: 2147483647
Year: 2002
Pages: 177

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