Lights, Camera, Action


Lights, Camera, Action!

In the previous steps, you completed all the coding that was required. Now you should compile the Java classes, create the WAR artifact and deploy onto Tomcat. Compiling the classes is a no-brainer. Just set the right classpath and invoke javac . The classpath should consist of the servlet-api.jar from Tomcat (This jar can be found in < TOMCAT_HOME > /common/lib , where TOMCAT_HOME is the Tomcat installation directory.) and all the JAR files from Struts distribution. They are found under jakarta-struts-1.1/lib directory. After compiling, you have to construct the WAR. Ant, Java community ‚ s de-facto build tool, can be used to perform these tasks . However we have chosen to create the WAR manually to illustrate which component goes where in the WAR. A clear understanding of the structure of Struts web applications is key to writing effective Ant scripts.

In Figure 3.2, you saw the directory structure of the Struts application. Now let us follow these steps to create the WAR that will look as shown in Figure 3.3 upon completion.


Figure 3.3: The structure of the WAR file.
  1. Create a directory called temp under the App1 directory.

  2. Copy all the contents of App1/web-root AS IS into the temp directory.

  3. Create a subdirectory called classes under temp/WEB-INF

  4. Copy the compiled classes into the directory WEB-INF/classes . Retain the package structure while doing this)

  5. Copy the App1Messages.properties into the directory WEB-INF/classes . Copy the file according to the java package structure. See Figure 3.3 for the final structure of the WAR.

  6. Create a directory lib under WEB-INF and copy all the JAR files from Struts distribution into the lib folder. These JAR files are required by your web application at runtime.

  7. Copy struts-bean.tld and struts-html.tld from Struts distribution into the WEB-INF directory.

  8. Zip (or jar) the temp directory into a file named App1.war . You WAR is ready now. Drop it into the webapps sub-directory in Tomcat. Start Tomcat and test it out!

Congratulations! You have successfully developed and deployed your first Struts application. However we are not done yet. Let us look at some practical issues that need to be addressed.




Struts Survival Guide. Basics to Best Practices
Struts Survival Guide: Basics to Best Practices (J2ee Survival Series)
ISBN: 0974848808
EAN: 2147483647
Year: 2004
Pages: 96

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