Wednesday, October 21, 2009

Recipe 1.2. Deploying the Struts Example Application










Recipe 1.2. Deploying the Struts Example Application




Problem



You want to deploy the Struts MailReader example application to
Tomcat.





Solution



If you don't already have the Tomcat running on your box, you can
download it from http://jakarta.apache.org/tomcat. This recipe
assumes that you are using Tomcat 5. Set environment variables for
Struts and Tomcat, copy the Struts example WAR file to Tomcat, and
start Tomcat.





If you are using Struts 1.2, the WAR file for the Struts example
application has been changed from
struts-example.war to
struts-mailreader.war.





The commands for a Windows machine are shown here:



C:\>set STRUTS_HOME=c:\jakarta-struts-1.1

C:\>set CATALINA_HOME=c:\tomcat5

C:\>copy %STRUTS_HOME%\webapps\struts-example.war %CATALINA_HOME%\webapps
1 file(s) copied.

C:\>%CATALINA_HOME%\bin\startup
Using CATALINA_BASE: c:\tomcat5
Using CATALINA_HOME: c:\tomcat5
Using CATALINA_TMPDIR: c:\tomcat5\temp
Using JAVA_HOME: c:\j2sdk1.4.2




The last command shown,
%CATALINA_HOME%\bin\startup, starts Tomcat. On
Windows, you will see Tomcat startup in a separate terminal window.
The output in this terminal window displays information about the
applications deployed and the state of Tomcat:


Jun 22, 2004 12:23:34 AM org.apache.catalina.core.StandardHostDeployer install
INFO: Installing web application at context path /struts-example from URL file:c
:/tomcat5/webapps/struts-example
Jun 22, 2004 12:23:38 AM org.apache.struts.util.PropertyMessageResources <init>
INFO: Initializing, config='org.apache.struts.util.LocalStrings', returnNull=tru
e
Jun 22, 2004 12:23:38 AM org.apache.struts.util.PropertyMessageResources <init>
INFO: Initializing, config='org.apache.struts.action.ActionResources', returnNul
l=true
Jun 22, 2004 12:23:40 AM org.apache.struts.util.PropertyMessageResources <init>
INFO: Initializing, config='org.apache.struts.webapp.example.AlternateApplicatio
nResources', returnNull=true
Jun 22, 2004 12:23:40 AM org.apache.struts.util.PropertyMessageResources <init>
INFO: Initializing, config='org.apache.struts.webapp.example.ApplicationResource
s', returnNull=true
Jun 22, 2004 12:23:40 AM org.apache.struts.webapp.example.memory.MemoryDatabaseP
lugIn init
INFO: Initializing memory database plug in from '/WEB-INF/database.xml'
Jun 22, 2004 12:23:40 AM org.apache.struts.validator.ValidatorPlugIn initResourc
es
INFO: Loading validation rules file from '/WEB-INF/validator-rules.xml'
Jun 22, 2004 12:23:41 AM org.apache.struts.validator.ValidatorPlugIn initResourc
es
INFO: Loading validation rules file from '/WEB-INF/validation.xml'
...
Jun 22, 2004 12:23:44 AM org.apache.coyote.http11.Http11Protocol start
INFO: Starting Coyote HTTP/1.1 on port 80
Jun 22, 2004 12:23:45 AM org.apache.jk.common.ChannelSocket init
INFO: JK2: ajp13 listening on /0.0.0.0:8009
Jun 22, 2004 12:23:45 AM org.apache.jk.server.JkMain start
INFO: Jk running ID=0 time=20/50 config=c:\tomcat5\conf\jk2.properties
Jun 22, 2004 12:23:45 AM org.apache.catalina.startup.Catalina start
INFO: Server startup in 49852 ms




You can use this output to verify that the application deployed and
that Tomcat successfully started and is running. In the output shown
above, you can see that Tomcat deployed the
struts-example.war file. In addition, the last
line indicates that Tomcat is running and the length of time it took
to start up.



On Unix/Linux, you would use similar commands:



$ export STRUTS_HOME=/usr/local/jakarta-struts-1.1

$ export CATALINA_HOME=/usr/local/tomcat5

$ cp $STRUTS_HOME/webapps/struts-example.war $CATALINA_HOME/webapps

$ $CATALINA_HOME/bin/startup.sh
Using CATALINA_BASE: /usr/local/tomcat5
Using CATALINA_HOME: /usr/local/tomcat5
Using CATALINA_TMPDIR: /usr/local/tomcat5/temp
Using JAVA_HOME: /usr/local/j2sdk1.4.2




Tomcat starts up as a background process. You can monitor the output
from Tomcat using the following:



$ tail -f $CATALINA_HOME/logs/catalina.out




Other than the different operating system file paths, the output will
be identical to the output on Windows shown previously.



Navigate your browser to http://localhost:8080/struts-example. You
should see the page shown in Figure 1-1.




Figure 1-1. Struts example application






Discussion



Using and examining the struts-example web
application is an excellent learning aid for Struts. Before you write
your first Struts application, you should understand how the
struts-example application works. The best way
to do this is to deploy the application. Experiment with the
interface and take the walking tour. You will want to follow along in
the walking tour by using your text editor or IDE to view the source
code.






You will need to download the Struts binary and source distributions
to deploy the struts-example. The WAR files are
included in the binary distribution. The source code is supplied in
the source distribution.





In addition to the struts-example application,
additional web applications demonstrate other Struts features as
shown in Table 1-1.



Table 1-1. Struts 1.1 example applications

WAR file to deploy



Description



struts-blank.war



A boilerplate Struts application.



struts-documentation.war



Struts User's Guide and tag library reference
documents.



struts-example.war



The seminal Struts Mail Reader example. Demonstrates most of the
basic core features and functions provided by Struts.



struts-exercise-taglib.war



An application that exercises the functionality of the Struts tag
libraries.



struts-upload.war



Shows how to use Struts support for file uploads.



struts-validator.war



Demonstrates the use of the Validator with Struts.



tiles-documentation.war



Includes Tiles documentation, sample layouts and tutorials.





Struts 1.2 reorganized the example applications. Table 1-2 lists the web applications contained in the
Struts 1.2 /webapps directory.



Table 1-2. Struts 1.2 example applications

WAR file to deploy



Description



struts-blank.war



A boilerplate Struts application.



struts-documentation.war



Struts User's Guide and tag library reference
documents.



struts-examples.war



Replaces the struts-exercise-taglib.war,
struts-upload.war, and
struts-validator.war. Combines the tag library,
upload, and Validator examples into one application.



struts-mailreader.war



The seminal Struts Mail Reader example. Demonstrates most of the
basic core features and functions provided by Struts.



tiles-documentation.war



Includes Tiles documentation, sample layouts and tutorials.







See Also



Recipe 1.1 discusses how to download Struts
and the details different distributions that are available.












    No comments: