# WebObjects/Web Applications/Deployment/Tomcat Deployment Details

Place for detailed information on deploying WebObjects applications in Tomcat.

## Assumptions

* Tomcat installation location: /usr/local/tomcat
* Apache configuration location: /etc/httpd
* Applications location: /usr/local/myapps
* Java installation location: /usr/java/jdk1.5.0_06

## Tomcat
### Common Libraries

Install all common libraries into /usr/local/tomcat/shared/lib, e.g.:

### War file

Install:

### Hosts

For each set of applications, here in sets of 10, create these files and directory structures. See the next section for the contents of ROOT.xml files.
Notice that each application has its own host directory, e.g. myapp01.mydomain.com, myapp02.mydomain.com, myapp03.mydomain.com, etc.
Place these under:
Group01
Group02

### ROOT.xml

For each host/application, use this template, changing the "myapp01" string, wherever it occurs below, to match the host's name, e.g. myapp01, myapp02.
The wo/NSLog4jLoggerName parameter is used for log4j logging, see below. Have it match the application's name.
Setup your own variables here as well for application specific configuration.

### server.xml

For each group above, install host definitions as such, matching the previous naming scheme, into that group's server.xml. Here are the entries for group02:
* the Connector port must be unique for each Service used on a single physical machine, and must match up with the corresponding modjk worker port used in the Apache worker.properties configuration file, covered below.
NOTE: per application deployment files and classes can be found in the applications work directory, but need not be altered at any time by the administrator.

### Logging
#### Log4j debug mode

Add this to your start of Tomcat to get explicit debug information from log4j. Log4j can be very frustrating, so this is key in debugging the steps it is taking:
See the below Tomcat startup command for details.

#### Getting started

Install the log4j properties file into Tomcat's common/clases directory:
If this location does not seem effective, try:
changing the path to the appropriate group for your application, e.g. from group01 to group02.
Commented lines can be uncommented, and the application's corresponding Tomcat server restarted, to output logging for a particular application. Here the example is for application named "myapp01"; this name is defined in the ROOT.xml file above by the wo/NSLog4jLoggerName parameter:
Another method to view an application's logging information is, e.g, to comment the appropriate line and restart the server:
This will output logging information for the myapp16 application to /usr/local/tomcat/logs/tomcat.log.

## Server Startup

Start each server up separtely. Environmental variables may be exported beforehand, or passed like so on the command line, before the executable is called:
Or start a Tomcat instance with log4j debugging on to determine what steps log4j is using in determining log settings and output:

## Server Shutdown

On Linux, this command will shutdown all java processes on the server, be careful:
or a particular process may be stipulated, e.g. 12203:
And sometimes Tomcat gets hung, be careful though, this will kill every single last java process on your system, no questions asked:
This will also work, in this case for the group01 server:

## Apache
### Core modjk Settings

Add to httpd.conf
And add /etc/httpd/worker.properties, containing:

### Virtual Hosts

Each virtual host contains such an entry, with specifics modified appropriately, e.g. change myapp02 to match your application's name:

### Rewrite Rules

Assure that apache has been built and/or installed to use mod_rewrite.
Then install /etc/httpd/mod_rewrite.conf:
This is just an example, you will have to figure this out for yourself in detail. Or figure it out and update this wiki with universal rules.

### Testing

Once the Tomcat servers are up and Apache running, hit a website:

## Auto Deployment

Touching the WAR file will redeploy all the applications. Replacing the WAR file with an updated version of your application, will auto deploy the new version systematically, one application per Tomcat server at a time. This can be followed by tailing /usr/local/tomcat/logs/tomcat.log.
Touching or updating of the ROOT.xml application files will reload/redeploy the application, and if any changes have been made, they will be picked up by the new deployment.

## Troubleshooting
### Rewrite Debugging

To get rewrite rule logging, add the following to the top of your rewrite fils:
Restart Apache and tail /tmp/mod_rewrite.log while hitting the website.

# Common Errors
## javax.servlet.UnavailableException: Error initializing servlet adaptor: access denied

Waiting on more information.

## javax.naming.NameNotFoundException: Name jdbc is not bound in this Context

See above comment. At present, not stopping the app from running fine. Looks like an unused entry in the web.xml file.

## javax.servlet.UnavailableException: Error initializing servlet adaptor: null

Unknown, but probably just a result of a previous complete failure of the app to start.

## java.lang.reflect.InvocationTargetException

Get rid of duplicate copy of jar file in the class path, most likely in /usr/local/tomcat/common/lib:
like so:

## javax.servlet.UnavailableException

Unknown, misconfiguration.