Previous section: JBoss Server Configurations

Adding our Tomcat Service

We are going to try building a minimal JBoss configuration that holds nothing but the Tomcat server. You might wonder why we don't simply get a recent copy of Tomcat, unpack it, and use it "stand-alone." The thing is, there are a number of JBoss services that can be made available to Tomcat, thus enhancing it. These include some transaction services, security, pooled datasources. Eventually you might want to add full Enterprise JavaBeans. This could be done by adding—piece by piece—JBoss components.

A quick warning: although I provide these instructions as though it were an intuitive process to me, I've got to confess I'm pretty new to this stuff myself. There was a lot of trial-and-error to get an idea of which components constitute the Tomcat "service" and what dependencies (jar libraries, other services, etc.) we have to take into consideration. Nevertheless, I think you'll agree the steps I outline here wont seem overly complex.

We will begin this mini-tutorial by assuming that you already created the new "custom" configuration as outlined in the last section.

Step 1: Copy "Tomcat" Service to the Custom Configuration

It's convenient to use the default or all server configurations as templates to grab the components we want to build into our new configuration. In the default configuration's deploy directory you can find the Tomcat service. It is a directory named jbossweb-tomcat50.sar. We want to move that directory to the deploy directory of our new custom configuration's deploy directory. This would look something like this:

cp -R server/default/deploy/jbossweb-tomcat50.sar server/custom/deploy/

Notice the funny directory name jbossweb-tomcat50.sar. I'm used to seeing files with .sar extensions, but this is a directory. What gives? Well it turns out this is an optional way of having a SAR archive in its unpacked state. I was able to use Java's JAR utility pack the contents of this directory in a file called, well, jbossweb-tomcat50.sar and it worked just the same. But having the service archive in its unpacked state makes it easy for us to go into the directory and make some modifications, which is what we're going to do next!

Step 2: Modify Tomcat's Configuration

The Tomcat service that we "borrowed" from the JBoss default configuration is set up to make use of some transaction and security services that are also found in default. Since we have pared our new configuration down to the bare minimums, the transaction and security services don't exist! Thus we will need to make a slight modification to Tomcat's configuration.

Go to the jbossweb-tomcat50.sar/META-INF directory and locate the jboss-service.xml file. We will have to comment out two small sections. First locate the section that looks like this:

<!-- A mapping to the server security manager service which must be
operation compatible with type
org.jboss.security.plugins.JaasSecurityManagerServiceMBean. This is only
needed if web applications are allowed to flush the security manager
authentication cache when the web sessions invalidate.
-->
<depends optional-attribute-name="SecurityManagerService"
proxy-type="attribute">jboss.security:service=JaasSecurityManager
</depends>

We will just want to move the end of the xml-comment field so that it also comments out the <depends> tag, so we'll have:

<!-- A mapping to the server security manager service which must be
operation compatible with type
org.jboss.security.plugins.JaasSecurityManagerServiceMBean. This is only
needed if web applications are allowed to flush the security manager
authentication cache when the web sessions invalidate.
<depends optional-attribute-name="SecurityManagerService"
proxy-type="attribute">jboss.security:service=JaasSecurityManager
</depends>
-->

Second we look for the line:

<depends>jboss:service=TransactionManager</depends>

And we'll comment it out as well:

<!--
<depends>jboss:service=TransactionManager</depends>
-->

Step 3: Copy over some needed libraries

This part was a tremendous exercise of trial and error on my behalf. (Okay, it probably only took 30 minutes.) You will need to copy over some JAR files from server/default/lib to server/custom/lib. Please copy over the following libraries:

javax.servlet.jar     javax.servlet.jsp.jar     jbosssx.jar     jboss-j2ee.jar     jboss.jar 

Step 4: Try it out!

In order to try out Tomcat, we need an appropriate Web application. I have a small, humble HelloWorld application that you can download. The file's name is SampleWeb.war and you will want to place it in the server/custom/deploy directory, right next to jbossweb-tomcat50.sar. If you now start the JBoss server with "bin/run.sh -c custom" you should see the additional following lines in JBosses console log:

INFO  [Embedded] Catalina naming disabled
INFO  [Http11Protocol] Initializing Coyote HTTP/1.1 on http-0.0.0.0-8080
INFO  [Catalina] Initialization processed in 1037 ms
INFO  [StandardService] Starting service jboss.web
INFO  [StandardEngine] Starting Servlet Engine: Apache Tomcat/5.0.28
INFO  [StandardHost] XML validation disabled
INFO  [Catalina] Server startup in 107 ms
INFO  [TomcatDeployer] deploy, ctxPath=/, warUrl=file:/Library/JBoss/4.0.0
/server/custom/deploy/jbossweb-tomcat50.sar/ROOT.war/
INFO  [WebappLoader] Dual registration of jndi stream handler: factory 
already defined
INFO  [TomcatDeployer] deploy, ctxPath=/SampleWeb, warUrl=file:/Library
/JBoss/4.0.0/server/custom/tmp/deploy/tmp18496SampleWeb-exp.war/
INFO  [Http11Protocol] Starting Coyote HTTP/1.1 on http-0.0.0.0-8080
INFO  [ChannelSocket] JK2: ajp13 listening on /0.0.0.0:8009
INFO  [JkMain] Jk running ID=0 time=1/77  config=null

Now, just to test the application, try browsing to http://localhost:8080/SampleWeb/servlet/HelloWorld and you should see a (humble) Hello World program running.

Conclusion

So what have we learned? Well, first we learned that we could add the Tomcat server by dropping one SAR archive into the deploy directory and 5 supporting JAR libraries into the lib directory. (If the jbossweb-tomcat50.sar had been "jarred up" into a single file, this would have meant only six files to install an entire web server!) We also learned that it's sometimes necessary to find out which services have dependencies (or are configured to use) other services. In this example we removed a configuration so Tomcat did not expect the transaction and security services.

In the next exercise we will try to do basically the same thing, but with JBoss's JMS messaging service.

Next section: Adding our JMS Service

 
 

Written material copyright © 2004 by Murray Todd Williams

Page last modified 10/29/2004 20:19