Deploying Web Applications
The next step after you have programmed and configured a Web application is to deploy it to Tomcat. You deploy an application to Tomcat by notifying it of a new application context. The first time you deploy a new application you must restart Tomcat. Thereafter you can reload the application as described in Reloading the Examples (xxii).
1 Specifying the Web Application Context
A context is a name that gets mapped to the document root of a Web application. The context of the Hello1 application is / hello1. The request URL http://localhost:8080/hello1/index.html retrieves the file index.html from the document root.
Tomcat can be notified of a new context in two ways:
-
Automatically. If you copy a Web application directory or WAR to <JWSDP_HOME>
/webapps, the context root for the application is automatically added to the Tomcat configuration. This is the approach used by the simpler applications (Hello1, Hello2, Date) discussed in the Web technology chapters.
-
By adding a context entry to Tomcat's configuration. This is the approach used by the Duke's Bookstore application discussed in the Web technology chapters. For example, here is the Context entry for the application discussed in Java Servlet Technology (page 367):
<Context path="/bookstore1"
docBase="../docs/tutorial/examples/web/bookstore1/build"
debug="0">
There are two ways to add this entry to Tomcat's configuration:
-
Edit the file <JWSDP_HOME>
/conf/server.xml. Since this can be error prone, we recommend the next approach.
-
Put an application-specific configuration file in <JWSDP_HOME>
/webapps. The Context entry for the application discussed in Java Servlet Technology (page 367) is in the file docs/tutorial/web/bookstore1/bookstore.xml. When the application is deployed, bookstore1.xml is copied to <JWSDP_HOME>
/webapps.
Note
Manual specification of the Context entry is a limitation of the current release of the Web Services Pack. Later releases will include an administration tool that will simplify this task.
2 Example
To deploy the Hello1 application:
-
Go to docs/tutorial/examples/hello1 and build and deploy the example by running ant. This runs the default ant target deploy which depends on the build target. The build target will spawn any necessary compilations and copy files to the docs/tutorial/examples/web/hello1/build directory. The deploy target copies the build directory to <JWSDP_HOME>
/webapps.
-
Start or restart Tomcat.
|