Making GlassFish v3 available using Apache2 and mod_jk

Wouter van Reeven 2
0 0
Read Time:4 Minute, 1 Second

The upcoming release of JEE 6 means that the next release of GlassFish, version 3, still is under development. However, it is stable enough to try out many features of JEE 6 already. apart from support for JEE 6, the integration with mod_jk has significantly improved recently. Earlier this week I followed the steps in this blog of Amy Roh to make GlassFish v3 available on port 80 using Apache2 and mod_jk. The steps described here are for Debian Lenny, but may equally well be followed for other Linux distributions or Windows.

Installing and configure Apache2 and mod_jk

Let’s start with installing Apache2 and mod_jk. On Debian Lenny, mod_jk is dependend on apache2-mpm. Fortunately, both apt-get and dselect will resolve all dependencies for you if you select mod_jk, so install everything you need for instance with

apt-get install libapache2-mod-jk

Installing mod_jk this way will ensure that the mod_jk module is enabled for Apache2. You can check and verify that with

$ ls -l /etc/apache2/mods-enabled/jk.load
lrwxrwxrwx 1 root root 25 2009-08-12 14:18 /etc/apache2/mods-enabled/jk.load -> ../mods-available/jk.load

In case the module is missing from the monds-enabled directory, you can enable it with

a2enmod jk

Once everything is installed you need to configure Apache and mod_jk. To keep my installation clean I created a directory called jk under the Apache2 config directory /etc/apache2. In this directory I placed my file, which reads

# Define 1 real worker using ajp13
# Set properties for worker1 (ajp13)

A minimum workers.properteis file should have worker.list, worker.worker1.type, and worker.worker1.port. That’s all for mod_jk.

As for Apache2, I had to do two things. first of all, I needed to add the configuration settings to enable mod_jk in the Apache2 httpd.conf file. On Debian, however, this file is empty and apache2.conf is used instead. This file gets overwritten when you upgrade Apache2, so the best way to include the mod_jk config is to create a new file under the /etc/apach2/conf.d directory and put everything in there.

So I created a file called /etc/apache2/conf.d/jk and put this in there:

# Where to find
JkWorkersFile /etc/apache2/jk/
# Where to put jk logs
JkLogFile /var/log/apache2/mod_jk.log
# Set the jk log level [debug/error/info]
JkLogLevel info
# Select the log format
JkLogStampFormat "[%a %b %d %H:%M:%S %Y] "
# JkOptions indicate to send SSL KEY SIZE,
JkOptions +ForwardKeySize +ForwardURICompat -ForwardDirectories
# JkRequestLogFormat set the request format
JkRequestLogFormat "%w %V %T"
# Locattion of shm file
JkShmFile /etc/apache2/jk/jk.shm

The only other thing to do is to specify which URL paths should be redirected to mod_jk. Debian by default uses Virtual Hosts and Apache2 requires that each Virtual Host has their own settings for which URL path to redirect. So I added these lines to /etc/apache2/sites-enabled/default within the <VirtualHost></VirtualHost> tags:

# Send everything for context /examples to worker named worker1 (ajp13)
JkMount /GFTest/* worker1

That’s it for Apache2.

Installing and configuring GlassFish v3

GlassFish v3 can be downloaded from this URL. I used promoted build 57 (which probably will be the next preview release) but build 53 or later will do. Since I set up everything on a server with no graphical UI I downloaded the zip, but the Windows or UNIX/Linux installer will also do. I unzipped the zip in /usr/local/glassfish.

After starting up GlassFish with

/usr/local/glassfish/glassfihv3/bin/asadmin start-domain

I had to create an HTTP listeren on port 8009 and enable jk on it. This can be done with these two commands

asadmin create-http-listener --listenerport 8009 --listeneraddress --defaultvs server jk-connector
asadmin set

Running a netstat afterwards to see if port 8009 was up revealed … no port 8009! The reason is that GlassFish v3 is OSGi enabled and only will start the Web container if a web application is deployed. So, I deployed a test application and port 8009 was taken as well! The result shows a count of rows in a table in my database displayed in a JSF 2.0 page based on this blog by Ed Burns (hence the similar text and colors):

About Post Author

Wouter van Reeven

Wouter is Java consultant at AMIS
0 %
0 %
0 %
0 %
0 %
0 %

Average Rating

5 Star
4 Star
3 Star
2 Star
1 Star

2 thoughts on “Making GlassFish v3 available using Apache2 and mod_jk

  1. Works great, one question though.
    Suppose you host several domains on your apache box and you connect it to Glassfish.
    How do you circumvent the context root of the application on glassfish?
    What you want is that domain_A goes to context-root_A and domain_B goes to context-root_B, without actually typing the context-root after the domain name.
    Is that possible?
    So if the URL is it redirects to glassfish to the context-root app_a.

  2. I think this is the clearest and most concise tutorial on how to setup Apache to work with Glassfish so far.

Comments are closed.

Next Post

ADF DataBinding: Yet another thing it does for you.

Today I encountered something that I have seen frequently. While developing an ADF application developers tend to invoke methods on an application module directly, instead of invoking them via the bindings framework. You might get some unexpected results and some additional work too… Correcting this behavior afterwards can be very […]
%d bloggers like this: