 |
Documentation
Users
Download
Get Involved
Hosted by:
|  |  |  |
Tomcat 4 Integration Sample
Tomcat 4 Integration Sample
|
How to integrate the Wrapper with Tomcat 4 |
Tomcat is normally run by executing startup.bat or startup.sh script to launch
the server and then executing shutdown.bat or shutdown.sh to stop the server.
This type of application is what the WrapperStartStopApp helper class was
designed for.
Installing the Wrapper files |
Download the latest version of the Wrapper and uncompress the archive into
the directory of your choice. Do the same with Tomcat.
Windows files |
Copy the Wrapper.exe file from the {wrapper.home}/bin directory
into the {tomcat.home}/bin directory. Template batch files are
available in {wrapper.home}/src/bin. Copy the files App.bat.in,
InstallApp-NT.bat.in and UninstallApp-NT.bat.in into the
{tomcat.home}/bin directory, renaming them as follows:
Tomcat.bat, InstallTomcat-NT.bat, and UninstallTomcat-NT.bat.
Next, copy the required library files, Wrapper.DLL and wrapper.jar,
from the {wrapper.home}/lib directory into the {tomcat.home}/lib
directory.
Finally, copy the template wrapper configuration file wrapper.conf.in
from the {wrapper.home}/src/conf directory into the
{tomcat.home}/conf directory, renaming it to wrapper.conf. We will
go over required modifications to wrapper.conf below.
|
Linux / Solaris files |
Copy the wrapper and realpath binaries from the {wrapper.home}/bin
directory into the {tomcat.home}/bin directory. Copy the template
script file from the {wrapper.home}/src/bin directory into the
{tomcat.home}/bin directory, renaming it to tomcat.sh. There are
two script files available. The first, bash.script.in should usually
be used for Linux. sh.script.in should be used for Solaris.
Make sure that the executable permission is set for all 3 files.
Edit the tomcat.sh file. Towards the top of the file, you will find
two tokens which need to be replaced. Replace the token "@app.name@"
with "tomcat", and "@app.long.name@" with "Tomcat 4 Server". No
other changes should be necessary.
Next, copy the required library files, libwrapper.so and wrapper.jar,
from the {wrapper.home}/lib directory into the {tomcat.home}/lib
directory.
Finally, copy the template wrapper configuration file wrapper.conf.in
from the {wrapper.home}/src/conf directory into the
{tomcat.home}/conf directory, renaming it to wrapper.conf. We will
go over required modifications to wrapper.conf below.
|
|
Setting up the wrapper.conf file |
The scripts that come with Tomcat are a bit complicated so that they will
work under all circumstances. In order to figure out how to configure
the Wrapper to launch Tomcat. You need to first figure out what the
actual command is that launches Tomcat. You can do this on Windows by
commenting out the @echo off at the top of the batch file. The same can
be done on unix by echoing the command to the console just before it is
executed..
On windows, the command used to launch Tomcat is as follows (The command
is actually all on one line):
"D:\Sun\j2sdk1.4.0\bin\java"
-Djava.endorsed.dirs="..\bin;..\common\lib"
-classpath "D:\Sun\j2sdk1.4.0\lib\tools.jar;..\bin\bootstrap.jar"
-Dcatalina.base=".." -Dcatalina.home=".." -Djava.io.tmpdir="..\temp"
org.apache.catalina.startup.Bootstrap start
|
It turns out that the shutdown script is exactly the same command. The
only difference is that the application parameter "start" is replaced
with "stop".
"D:\Sun\j2sdk1.4.0\bin\java"
-Djava.endorsed.dirs="..\bin;..\common\lib"
-classpath "D:\Sun\j2sdk1.4.0\lib\tools.jar;..\bin\bootstrap.jar"
-Dcatalina.base=".." -Dcatalina.home=".." -Djava.io.tmpdir="..\temp"
org.apache.catalina.startup.Bootstrap stop
|
The script resolves all absolute paths. To make this example more
portable, we will modify the absolute paths to be relative to the bin
directory, where the Wrapper binary is located. We will also assume
that java can be found on the system path.
Breaking up the commands above, there are several things to look for.
The first is the command used to launch the JVM. If the above command,
this is "D:\Sun\j2sdk1.4.0\bin\java". Assume that the java command is
available on the path, the following property needs to be set in the
wrapper.conf file:
wrapper.java.command=java
|
The next step is to setup the classpath. To make the configuration
portable, the Wrapper requires that each classpath element be set as a
different property. It is also necessary to include the wrapper.jar
file. If you are using JSP, then Tomcat requires that the tools.jar
file, included with the JDK, be included in the classpath as well.
You can either set the classpath to point to the location of the jar
in the JDK, or copy it into tomcat's tools directory. Here we assume
the later. The classpath should be set as follows in the wrapper.conf
file:
wrapper.java.classpath.1=../lib/wrapper.jar
wrapper.java.classpath.2=../lib/tools.jar
wrapper.java.classpath.3=../bin/bootstrap.jar
|
The Wrapper will need to be able to locate its native library. This
should already be set in the default wrapper.conf file, but make sure
that the following property is set:
wrapper.java.library.path=../lib
|
Tomcat requires a number of properties be set when the JVM is launched.
These are set as follows:
wrapper.java.additional.1=-Djava.endorsed.dirs="../bin;../common/endorsed"
wrapper.java.additional.2=-Dcatalina.base=".."
wrapper.java.additional.3=-Dcatalina.home=".."
wrapper.java.additional.4=-Djava.io.tmpdir="../temp"
|
Next the class used to launch Tomcat must be specified. In the commands
above, this is org.apache.catalina.startup.Bootstrap. However we will
be relying on a helper class to control the life cycle of Tomcat. Set
the main class as follows:
wrapper.java.mainclass=com.silveregg.wrapper.WrapperStartStopApp
|
The WrapperStartStopApp still needs to be told how to start and stop
Tomcat. This is done by passing parameters to the class when it is
started. Set the application parameters as follows:
wrapper.app.parameter.1=org.apache.catalina.startup.Bootstrap
wrapper.app.parameter.2=1
wrapper.app.parameter.3=start
wrapper.app.parameter.4=org.apache.catalina.startup.Bootstrap
wrapper.app.parameter.5=true
wrapper.app.parameter.6=1
wrapper.app.parameter.7=stop
|
The Bootstrap class is used to both start and stop Tomcat. In each case,
a single parameter is passed in. "start" to start Tomcat, and "stop" to
stop it. When stopping Tomcat, the "true" flag specifies that the JVM
should not exit until all non daemon threads have completed.
The last step is to set the name of the pid file to use, for unix
systems, and the name and description of the NT Service, for Windows
systems:
wrapper.pidfile=/var/run/tomcat.pid
wrapper.ntservice.name=tomcat
wrapper.ntservice.displayname=Tomcat 4 Server
wrapper.ntservice.description=Tomcat 4 Server
|
If you applications make use of a database, then on Windows systems, you
should also make sure that the database is always started before Tomcat
when running as a service:
wrapper.ntservice.dependency.1=MySQL
|
|
Testing the configuration |
You should now be able to run Tomcat using the scripts we installed
above. See the Launch Overview
section for an explanation of how the scripts work. On NT, make sure
that the installation works as a console application before attempting
to run as a service.
If you find any problems with this sample, please let us know so we can
get them fixed.
|
|
|  |