Problem using MySQL JDBC on Tomcat 5.5 and Ubuntu 8.04

, , , Comments Off

Normally when I build a web application that connects to a MySQL database, I would place the mysql-connector-java-bin.jar file into the WEB-INF/lib of the web application.

However, when I deployed the application on Tomcat 5.5 on Ubuntu 8.04 I got an exception: java.lang.ClassNotFoundException: com.mysql.jdbc.Driver

I couldn’t find the reason which caused the exception, so I did a quick fix by placing the jar file into the Tomcat’s common lib directory.

$ cp mysql-connector-java-bin.jar /usr/share/java
$ cd /usr/share/tomcat5.5/common/lib
$ ln -s ../../../java/mysql-connector-java-bin.jar mysql-connector-java-bin.jar

Problems with Ubuntu 7.10 and Tomcat 5.5

, Comments Off

Ubuntu 7.10 (Gutsy Gibbon) was released on Oct 18, 2007, and like most administrators I decided to take advantage of the release and upgraded my current system 7.04 (Feisty Fawn). Overall, the upgrade went well and I didn’t run into any trouble during the upgrade process. However, afterwards I found some side effect on the my web applications running on Tomcat:

  1. Log4j was no longer logging anything into the log files.
  2. I was getting the following exception in the catalina.log file when attempting to dynamically render an image with a java servlet.

    java.lang.UnsatisfiedLinkError: /usr/lib/jvm/java-1.5.0-sun-1.5.0.13/jre/lib/i386/libawt.so: Can't load IA 32-bit .so on a IA 32-bit platform
    at java.lang.ClassLoader$NativeLibrary.load(Native Method)
    at java.lang.ClassLoader.loadLibrary0(ClassLoader.java:1751)
    at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1668)
    at java.lang.Runtime.loadLibrary0(Runtime.java:822)
    at java.lang.System.loadLibrary(System.java:993)
    at sun.security.action.LoadLibraryAction.run(LoadLibraryAction.java:50)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.awt.Toolkit.loadLibraries(Toolkit.java:1509)
    at java.awt.Toolkit.<clinit>(Toolkit.java:1530)
    at java.awt.Font.<clinit>(Font.java:141)
    ....

It turned out that the Java JVM was upgraded to 1.5.0_13-b05 which contained several bugs. Not knowing of anyway to downgrade my JVM to it’s preivous version, I decided to install Java 6 and use it as the JVM for Tomcat.

To install Java 6 for Ubuntu:
$ apt-get install sun-java6-jdk

To configuring Tomcat to run on the Java 6 JVM:
$ nano /etc/default/tomcat5.5

Uncomment or add the following line:
JAVA_HOME=/usr/lib/jvm/java-6-sun

Restart the Tomcat server:
$ /etc/init.d/tomcat5.5 restart

Afterwards, everything was running back to normal!

Tomcat 5.5 Doesn’t Start in Ubuntu 7.10

, Comments Off

This is related to one of the web application deployed in Tomcat containing the
Apache Common Loggings jar file inside the WEB-INF/lib directory. To
fix this issue, place a copy of the commons-logging jar file inside the
Tomcat’s common endorsed directory.

$ cp commons-logging-1.1.jar /usr/share/java
$ cd /usr/share/tomcat5.5/common/endorsed
$ ln -s ../../../java/commons-logging-1.1.jar commons-logging-1.1.jar

Tomcat 5.5 Doesn’t Start in Ubuntu 7.04

, Comments Off

For the Ubuntu installation, Tomcat’s log file is set to be a pipe, but

Tomcat can’t seem to start with it. A quick fix will be to recreate it
as a regular file with the same security settings and restart Tomcat.

$ cd /var/log/tomcat5.5
$ sudo rm catalina.out
$ sudo touch catalina.out
$ sudo chown tomcat55:nogroup catalina.out
$ sudo chmod 600 catalina.out

Integrating Tomcat and Apache with mod_jk Connector

, , Comments Off

Using the mod_jk connector is an alternative but more complex method of integrating Tomcat and Apache together. The concept behind this method is to have Apache serve the static content of the website, and Tomcat to serve the Java related content. This could be a better alternative if your website contains mostly HTML pages.

The mod_jk connector along with mod_proxy_ajp are the only recommend methods of Tomcat and Apache integration. mod_jk is still actively under development, and is very stable for production servers, as well it supports both Apache 1.3, and 2.x. Other past alternatives like mod_webapp, mod_jserv, mod_jk2 are not longer supported and are consider deprecated.

mod_jk Package Issue for Ubuntu

For Ubuntu 7.04 there is an error in the mod_jk package. It currently has two packages for mod_jk:

  • libapache-mod-jk which depends on apache
  • libapache2-mod-jk2 which depends on apache2

As mention previously, mod_jk2 is already deprecated and mod_jk works for both Apache 1.3, and 2.x.

To properly configure Tomcat and Apache to use mod_jk the connector must be manually, build and set up from the source.

Installing and Configuring mod_jk

Download and extract the latest connector from the Tomcat website http://tomcat.apache.org/download-connectors.cgi, then configure and build it:

$ cd tomcat-connectors-1.2.23-src/native
$ ./buildconf.sh
$ ./configure --with-apxs=/usr/bin/apxs2
$ make; make install

Verify the mod_jk.so module exist in the apache module directory /usr/lib/apache2/module.

Note: The programs are required to configure and build the connector: automake, autoconf, libtoolize, and apxs2. To obtain these programs install the following packages in Ubuntu: libtool, automake, and apache2-threaded-dev

libtool error when compiling

On some systems the 'make' command will fail with the following error:

libtool: compile: unable to infer tagged configuration
libtool: compile: specify a tag with `--tag'

This is due to libtool not using the correct gcc when compiling. A workaround would be to add the parameter '--tag CXX' inside the Makefile.

$ cd  tomcat-connectors-1.2.23-src/native/common
$ nano Makefile

Inside the Makefile the change line from:

LIBTOOL = /usr/share/apr-1.0/build/libtool --silent

to:

LIBTOOL = /usr/share/apr-1.0/build/libtool --silent --tag CXX

Creating the workers.properties

Create a workers.properties file in the Apache configuration directory and add the following lines to it.

$ nano /etc/apache2/workers.properties

# This file provides minimal jk configuration properties needed to
# connect to Tomcat.
workers.tomcat_home=/usr/share/tomcat5.5
workers.java_home=/usr/lib/java-1.5.0-sun
ps=/
# Define 1 real worker using ajp13
worker.list=worker1
# Set properties for worker1 (ajp13)
worker.default.port=8009
worker.default.host=localhost
worker.default.type=ajp13
worker.default.lbfactor=1

Configure Apache for mod_jk

Create the jk module configuration files for Apache

$ nano /etc/apache2/mods-available/jk.load

LoadModule jk_module /usr/lib/apache2/modules/mod_jk.so

$ nano /etc/apache2/mods-available/jk.conf

<IfModule mod_jk.c>
    # Where to find workers.properties
    JkWorkersFile /etc/apache2/workers.properties
    # 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"

    # Globally deny access to the WEB-INF directory
    <LocationMatch '.*WEB-INF.*' >
         Order deny,allow
         Deny from all
    </LocationMatch>
</IfModule>

After creating the configuration files you can now enable the jk module for Apache

$ a2enmod jk

Sending JSP and Servlets through mod_jk

Inside the virtual host you can mount JSP and Servlet context to the worker define in the workers.properties file. For example to mount the JSP and Servlet examples from Tomcat add the following lines:

JkMount /jsp-examples/*.jsp worker1
JkMount /servlets-examples/servlet/* worker1

Apache DirectoryIndex

If your website uses index.jsp it must be download inside the DirectoryIndex of Apache. Modified the file /etc/apache2/mods-enabled/dir.conf and add index.jsp to the list.

WP Theme & Icons by N.Design Studio
Entries RSS Comments RSS Log in