Recipe13.1.Deploying an Application Automatically


Recipe 13.1. Deploying an Application Automatically

Problem

You want to be able to test and retest your web application in Tomcat without having to redeploy the application whenever a change is made to a Java class or JSP page.

Solution

Use the development directories of your application as the actual directories that the application server uses for the deployed application. For Tomcat, you would create a Context element immediately before the </Host> end tag in the conf/server.xml file (under your CATALINA_HOME top-level directory).

<Host...>    ...    <Context path="/struts-cookbook"           docBase="/path/to/myapp/web"       reloadable="true"/> </Host>

Discussion

This recipe is not particular to Struts but is applicable to any J2EE-based web applications. However, the Solution is particular to Tomcat. If you aren't using Tomcat, your application server most likely uses a similar mechanism. If you use the Solution, you won't have to deploy your application when changes are made; your application will always be deployed.

The docBase attribute specifies a file path to your deployment directory. If you're using Windows, you'll need to include the drive letter on the path as shown here:

docBase="c:/Documents and Settings/My App/web"

The structure of this directory must match the structure of a valid J2EE web application. Its contents would look something like this:

/index.html /welcome.jsp /feedback.jsp /images/banner.gif /WEB-INF/web.xml /WEB-INF/struts-config.xml /WEB-INF/classes/ApplicationResources.properties /WEB-INF/classes/com/foo/MyBar.class /WEB-INF/classes/... /WEB-INF/lib/struts.jar /WEB-INF/lib/...

By setting reloadable="true" Tomcat will monitor the WEB-INF/classes and WEB-INF/lib directories of your application. When changes occur in either of these directories, Tomcat will restart your application and the changes will get picked up. Setting reloadable to true will negatively impact performance and should only be used in development. If you're making JSP changes, you don't have to set reloadable to true. Tomcat detects changes to JSPs automatically, translating and recompiling on the fly. However, if you change configuration files, such as the struts-config.xml, web.xml, and validation.xml, you'll need to restart the web application manually as these files are read on application initialization.

This deployment approach increases your productivity by reducing the code-compile-test cycle time. However, the Solution depends on the platformboth the application server and the operating systemand is not viable for production and QA deployments. Therefore, your application should include a platform-independent build script. Ant (http://ant.apache.org) provides an excellent framework for these scripts.

See Also

Recipe 1.7 shows you how to define a repeatable process for the compile-deploy cycle.

Recipe 13.4 describes how to enable remote debugging of a web application running in a different JVM.

You can find additional details on configuring Tomcat at http://jakarta.apache.org/tomcat.



    Jakarta Struts Cookbook
    Jakarta Struts Cookbook
    ISBN: 059600771X
    EAN: 2147483647
    Year: 2005
    Pages: 200

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