A war for Tomcat

It could be interesting to follow the procedure to deploy a web application on Tomcat for Windows.

Let's assume we already have it, nicely packed in a .war file. If this doesn't say much to you, see ho to create a simple servlet with NetBeans. As a result you get a Web ARchive, and what we are going to do here is to deploy it on Tomcat "manually".

First thing, we have to run Tomcat.

One way of doing it is calling directly the "startup" utility from the binary Tomcat directory. Before doing it from a shell we have to set a few environment variable:
JAVA_HOME to let Tomcat know where is the Java Virtual Machine we want to run, in my current case:
set JAVA_HOME=C:\Program Files (x86)\Java\jdk1.6.0_20
Then we set a couple of variable, CATALINA_BASE and CATALINA_HOME. The first one refers to the configuration stuff for an instantiation of Tomcat, the second one is for all the Tomcat generic stuff. As catalina base directory I use here the one generated by NetBeans:
set CATALINA_BASE=C:\Users\(...)\.netbeans\6.9\apache-tomcat-6.0.26_base
set CATALINA_HOME=C:\Program Files (x86)\Apache Software Foundation\Apache Tomcat 6.0.26
Finally, we set the path in a way that windows could find the Tomcat executable files. Since I would use a shell just for running Tomcat, I can set the path just to this directory:
set PATH=C:\Program Files (x86)\Apache Software Foundation\Apache Tomcat 6.0.26\bin
I put all these "set" statements in a batch file, I run it, and now we are ready to launch Tomcat calling "startup". This command would open another DOS shell and display the startup log for Tomcat. We should see just "INFO" log messages, and the last message should state how long it took to start Tomcat up.

Once we have Tomcat up, we can send it down, calling "shutdown". A bit more log would be displayed in the Tomcat shell window, and then it will be closed. In our main shell, where we launched the shutdown procedure, we should see a few log lines acknowledging us of the directory used to perform the shutdown. A mismatch between the startup and the shutdown environment usually resolves in a disaster - meaning, no shutdown performed.

Among the different directory we set through the environmental variables, it is worth having a closer look at the CATALINA_BASE one. Here we find everything linked to our specific Tomcat execution. Configuration files, log files, working files used by Tomcat during the run and so on. If something goes wrong, this is a good place to start our investigation.

Here, under the conf directory, we find also the tomcat-user.xml file, that defines users, passwords and access privileges. Since this files have been created by NetBeans, here will find the user "ide" that has the roles of manager and admin. We could use it this one, or create a new one.

So, we have Tomcat up and running - if we didn't change the default, we should see the Tomcat homepage accessing "http://localhost:8084/" with our preferred web browser - we know the password of a user registered in the tomcat-user configuration file with manager privilege, and we have a web archive we want to add to this instance of Tomcat.

We need to access the "Tomcat manager" page, and we can do it by clicking on the appropriate link in the "Administration" section of the main Apache Tomcat page. Here we are request of a good user/password, we have it, so we reach the "Tomcat Web Application Manager" page.

Here we see all the applications currently available. To add a new one, we can go to the bottom of the page "WAR file to deploy" section, and select the war file we want to use.

The war will be copied in our CATALINA_BASE folder, under webapps, the files in the war will be extracted and made available to Tomcat.

No comments:

Post a Comment