Installing the JK Connector

The JK connector is what Apache and Tomcat use to "speak" with each other. It's a separate piece of software, distinct from both Apache and Tomcat. There is also a JK2 connector, but in this HOWTO we will be working with the JK connector. The goal here is to get JSP and servlets to run on port 80, without having to set Tomcat to run on port 80. It is possible to run Tomcat on port 80 as a stand-alone web server, but in many situations, there is a need to use Apache on port 80. The connector acts as the conduit between Apache and Tomcat in that scenario.

1. Download the JK connector here: http://jakarta.apache.org/builds/jakarta-t....2.1/bin/win32/. In our case, we want the file called mod_jk-2.0.43.dll because we are using Apache 2.0.43.

2. The file is an Apache module, it is NOT a Tomcat JAR file or WAR file. It doesn't belong in Tomcat's directory structure, it belongs in a place where Apache can find it. For Apache 2.0.43, that is APACHE_HOMEmodules, where APACHE_HOME is equal to your Apache install location. In our case, that is c:apacheApache2, so we want to put the JK DLL file into c:apacheApache2modules. You should end up with a file called c:apacheApache2modulesmod_jk-2.0.43.dll on your hard drive. If you notice that the other files in c:apacheApache2modules end in "*.so", that's OK. Both "*.so" and "*.dll" are valid Apache module extensions on Windows systems.

NOTE: from now on, APACHE_HOME = c:apacheApache2 or the name of your Apache home directory.

3. Edit Apache's configuration file. It is located in APACHE_HOMEconf and is called httpd.conf. Don't be nervous, there is a copy in the same directory called httpd.default.conf. You can always revert back to the default settings if you need to by copying that file.

4. Edit httpd.conf in your favorite text editor. DO NOT edit it in Microsoft Word!! Use Notepad or another editor. Scroll down to where you see a bunch of lines that say "LoadModule". At the end of this list, add a line that says:

LoadModule jk_module modules/mod_jk-2.0.43.dll


Save the file you just edited to the APACHE_HOMEconf directory, and before going any further, verify that you have things setup correctly. Open a command prompt window by clicking Start->Run and typing cmd and clicking OK. At the prompt, type c:apacheApache2binApache.exe -t and hit return. You should see a message that says "Syntax OK". If you don't see this message, go back to Step 1 and review any changes you have made to determine the error. Note that using "-t" on the command line WILL NOT start the Apache service, it just checks the changes that you made to httpd.conf for any errors.

5. Edit Tomcat's configuration. First, make a copy of c:tomcattomcat-4-1-18confserver.xml. Now edit c:tomcattomcat-4-1-18confserver.xml. Look for a line that says




Just below that line, add the following:




Now look for a line that says




Just below that line, add the following:


(note that this line, while similar to the first one, is different)

Save the changes you made to server.xml. Restart the Tomcat service. Wait a few seconds, and then check to see if there is a file called mod_jk.conf in c:tomcattomcat-4-1-18confauto (c:tomcattomcat-4-1-18confautomod_jk.conf). If there is, all is well. If there isn't, go back to the beginning of Step 5 and verify the changes you made to server.xml.

By adding the two Listener elements to server.xml, you are causing Tomcat to generate the necessary Apache configuration directives for mod_jk automatically. You don't need to type them by hand. This is a very convenient feature, but it is optional. If you want to configure Apache by hand, you are welcome to do so, but that is not covered here in this HOWTO.

6. Almost done on the Tomcat side. JK, in the Apache module, uses the concept of a "worker" to send and receive info to Tomcat. We need to tell the worker where Tomcat is, and what port we want it to use. This is done with a workers.properties file. We want to put the workers.properties file into c:tomcatTomcat-4-1-18confjk, though it can be anywhere. So, open up Notepad or your favorite text editor with a blank file, and add the following lines to it:

# BEGIN workers.properties
# Definition for Ajp13 worker
worker.list=ajp13
worker.ajp13.port=8009
worker.ajp13.host=localhost
worker.ajp13.type=ajp13
# END workers.properties



Save the file as c:tomcatTomcat-4.1.18confjkworkers.properties. Note that the default name for a JK worker is "ajp13". You can call it what you like, but my advice is don't change it until you have a completely working installation and can see how all the pieces fit together.

7. Now go back to Apache's httpd.conf file, and edit it (c:apacheApache2confhttpd.conf). At the very end of the file, add the following line:

Include c:/tomcat/tomcat-4-1-18/conf/auto/mod_jk.conf



Save the file, and verify your syntax by running c:apacheapache2binapache.exe -t at a command prompt. You should see a message that says "Syntax OK". If you don't see this message, review the edits you just made and make sure that c:/tomcat/tomcat-4-1-18/conf/auto/mod_jk.conf and workers.properties actually exist where they should.

Installation Checklist

OK, that was a lot of work. By now, you should have the following environment:


JDK installed in c:j2sdk1.4.1_01
JAVA_HOME environment variable set for all users (System level) to c:j2sdk1.4.1_01
The JK DLL downloaded from the Jakarta site and placed in c:apacheApache2modules
Apache installed in c:apacheapache2, with "Syntax OK" messages after both the LoadModule edit and the Jk/Include edit, and able to view the Apache welcome page at http://localhost
Tomcat installed in c:tomcattomcat-4-1-18, successfully restarted with both Listener element edits to server.xml, and able to view the Tomcat welcome page and execute the Tomcat examples at http://localhost:8080
A file called workers.properties located in c:tomcatTomcat-4-1-18confjk
Checking Your Installation

1. Start Tomcat as a service using the service control panel. Start->Application Tools->Services. If Tomcat is running, stop it and then start it. Wait a few seconds before continuing.

2. Start Apache using the Apache Monitor in your System Tray. Right click on the System Tray icon, and choose "Open Apache Monitor", then click "Start". Wait a few seconds before continuing.

3. Verify the Apache welcome page at http://localhost

4. Verify the Tomcat examples at http://localhost:8080/examples/jsp/index.html

5. Verify Tomcat examples available on port 80 at http://localhost/examples/jsp/index.html

If you can execute the Tomcat examples successfully without "8080" on the URL, then mod_jk is working correctly.

For more info, consult the Tomcat documentation as well as the tomcat-user mailing list. If you want to use this HOWTO for something other than "localhost", then all you have to do is use "www.your-domain.com" everywhere it says "localhost". My advice in that scenario would be to copy the existing, default Host container in Tomcat's server.xml, and change the "name" parameter to "www.your-domain.com", then restart Tomcat (to re-gen mod_jk.conf with the new hostname) and restart Apache. Making a copy of the localhost Host container in server.xml will leave the localhost container as a failsafe default, which might cut down on problems in the future.

NOTE: in Tomcat, virtual hosts are "Hosts". That is, as far as Tomcat is concerned, localhost is a virtual host. So, if you want to setup www.servers-a.com and www.servers-b.com, you just need more copies of the Host container included in the default server.xml that comes with Tomcat. Doing it in production is a little more complicated than that, but that's the essence of how to get Tomcat to work for more than localhost. Because this HOWTO describes using the Apache auto-config option of JK, getting Tomcat to work with your virtual hosts means Apache will work. This means that you can test your URL and your application contexts using ":8080" on your URL without affecting Apache. When you have it working, simply restart Apache so that it picks up the new mod_jk.conf file generated by Tomcat and you should be well on your way.