Apache Tomcat Windows service ignoring JAVA_HOME environment variable

I'm trying to get Apache Tomcat set up on a Windows Server 2003 machine. If I use the command line version (catalina.bat start) it all works fine, but if I try and use it as a Windows Service it seems to pick up the wrong value for JAVA_HOME - it ignores the environment variable I have set, and it's using the runtime path rather than the JDK path. As a result, my scripts won't compile and the app fails to run.

I'm using pretty old version of everything: Tomcat 4 and Java 1.4.2_19 (it's a legacy app that I don't have time to update at the mo - I just want to get it running, for phase 1).

I have the JDK installed to C:\j2sdk1.4.2_19 and Tomcat installed to C:\Program Files\Apache Software Foundation\Tomcat 4.1. The "Java Virtual Machine" setting for the service is set to C:\j2sdk1.4.2_19\jre\bin\client\jvm.dll. The JAVA_HOME environment variable is set to C:\j2sdk1.4.2_19.

When I try and launch my app, it writes the following error to the log:

Unable to find a javac compiler; com.sun.tools.javac.Main is not on the classpath. Perhaps JAVA_HOME does not point to the JDK. It is currently set to "C:\j2sdk1.4.2_19\jre"

i.e. it's added an extra "\jre" to the JAVA_HOME that shouldn't be there!

I also wondered whether it might be a registry setting somewhere, but I looked in all the obvious places. HKEY_LOCAL_MACHINE\SOFTWARE\Apache Software Foundation\Procrun 2.0\Tomcat4\Parameters\Java\JavaHome is set to the same as the JAVA_HOME environment variable, as is the JavaHome key under places like JavaSoft\Java Development Kit\1.4 and JavaSoft\Java Runtime Environment\1.4.2_19.

I'm starting to get rather frustrated trying to figure out why it won't work!


Solution 1:

I fixed it in the end by firing up a command window, setting JAVA_HOME appropriately, then running the following scripts from Tomcat's bin directory:

service.bat remove
service.bat install

I don't know how it did it, but that reconfigured the service to use the new value of JAVA_HOME.

Solution 2:

Check the appropriate registry key. Here is mine:

HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Apache Software Foundation\Procrun 2.0\Tomcat7.55\Parameters\Java

change the Jvm key value