Originally Published: Tuesday, 2 October 2001 Author: Henry Chen
Published to: enhance_articles_sysadmin/Sysadmin Page: 4/6 - [Printable]

Serving Java from Linux

Ever want a server on your box that can serve JSP and Java Servlets but don't want to pay big money for a commercial solution? Then Linux.com has the article for you. Follow author Henry Chen into the land of the sun.

  << Page 4 of 6  >>

Mod_jk

Technically speaking, your server can already serve Java pages.  However, according to Tomcat's own documentation, the web server that comes with Tomcat is not very good. Apache is a more robust web server.  So, we are going to use the Apache web server to do all the static pages and use Tomcat only for Java related files.  To accomplish this, we need a module that will pass the processing of Java files from Apache to Tomcat.  This is mod_jk.

We will also take advantage of the fact that Red Hat Linux 7.1 ships with an Apache server to which you can dynamically add modules.  We will make a mod_jk module to plug into the existing Apache server.  First, we get mod_jk from Tomcat's source tarball and we need apxs which is in the apache-devel RPM.  You are still the root user to type:

cd ~$username
rpm -ivh apache-devel-1.3.19-5.i386.rpm
cd /usr
tar -xzf ~$username/jakarta-tomcat-3.2.3-src.tar.gz
cd jakarta-tomcat-3.2.3-src/src/native/apache1.3

Setup the environment variables so that the makefile will work, then run make: (these are for bash, if you are not using bash or sh, these will not work)

TOMCAT_HOME=/usr/tomcat ; export TOMCAT_HOME
JAVA_HOME=/usr/java/jdk ; export JAVA_HOME
cp Makefile.linux Makefile
make

This will create mod_jk.so  Copy this file to Apache's module directory:

cp mod_jk.so /etc/httpd/modules

That's it.  Now, we have to configure the Apache server.

Apache

By default, the Apache server does not run on boot up.  Let's change that first:

mv /etc/rc3.d/K15httpd /etc/rc3.d/S15httpd

Now edit the Apache configuration file by: vi /etc/httpd/conf/httpd.conf  scroll down to just before the### Section 3: Virtual Hosts bit and insert this line:

include /usr/tomcat/conf/mod_jk.conf-auto

This is the path to the configuration file that Tomcat creates automatically every time it is started.  Unfortunately, it puts the modules in the wrong place so we have to fix that:

ln -s ../../usr/lib/apache /etc/httpd/libexec

This is obviously the lazy way.  You can also write your own mod_jk related configuration lines in httpd.conf.  I chose this method only because the automatically generated configuration file does not do anything bad. 





  << Page 4 of 6  >>