I recently ran into a java.lang.OutOfMemoryError exception after moving a Tomcat Web Application from a 32-bit system to a 64-bit system. Not being able to give the JVM more memory, I decided to install a 32-bit JDK on the machine. Getting a 32-bit Tomcat install working on a 64-bit system gave me a bit of trouble, so I decided to write this article.

Installing a 32-bit JDK is very easy. First, download the right package from the sun download site: http://java.sun.com/javase/downloads/index.jsp and extract it. To extract the .bin file, you need to make sure to make the .bin file executable. After that, you can run the file and it should extract itself to the current directory. You can now use the JDK by referencing it directly or by setting it as an alternative using the appropriate instructions. For the purpose of this article however, we don’t need to get into that. Next, you will need to update your start/stop scripts to take advantage of the new JDK.

Unfortunately, you still have more to do because the start/stop scripts use JSVC to control the Tomcat daemon. If you try to startup tomcat after referencing the new JDK, you will notice that you get an error stating that it cannot locate a valid JVM. This is because the JSVC that has been installed, is a 64-bit binary and is looking for a 64-bit JVM. You will now need to recompile JSVC as a 32-bit binary so that you can use it with your 32-bit JDK. This is where things get a little tricky. After some googling, I found the following instructions Unfortunately, these instructions didn’t work for me as is.

To compile JSVC, you will first you need to download and extract the JSVC source. Next, make sure you have lib32gcc1 and libc6-dev-i386 installed. On a Debian system you can do this with the following command:

sudo aptitude install lib32gcc1 libc6-dev-i386

If you do not have the packages installed, aptitude will prompt you to install the packages. Next, run the following configure commands to configure and build JSVC:

cd /path/to/jsvc/src/native/unix/
CFLAGS=-m32 CPPFLAGS=-m32 CCASFLAGS=-m32 LDFLAGS="-L/path/to/32/bit/shared/libraries/" ./configure --with-java=/path/to/32/bit/jdk/ --build=i686-pc-linux-gnu
cd native/
gcc -m32 -L/path/to/32/bit/shared/libraries/ -ldl -lpthread jsvc-unix.o libservice.a -o ../jsvc

On a Debian machine the path to your shared libraries might be:


By this point, you should have a jsvc binary in your /path/to/jsvc/src/native/unix/ directory. You can move this where ever you like and reference it from your tomcat start/stop scripts. Now, your done!