9

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!

andygeers
  • 373
  • 1
  • 4
  • 10

3 Answers3

7

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.

andygeers
  • 373
  • 1
  • 4
  • 10
  • 1
    Service.bat is similar to catalina.bat, but has an "create service" section. Like catalina.bat, he tries to find the JAVA_HOME variables, and many others, and like in catalina.bat, u can configure things like memory and so on. I recommend you open service.bat and investigate, because there's some params that will be interesting, like the name of the service. That Second run on service.bat just detectect correclty the Java Variables (if unmodified, catalina y service are quite similar). That's why works. – Carlos Garcia Jan 26 '11 at 08:21
  • I would be careful about doing this, because it will remove your entire Service configuration and replace it with a new one. If you have custom e.g. system properties, etc. they will all be lost. It would be better to run `tomcatXw.exe` (where `X` is your Tomcat major version) and edit the JRE home directory there to keep your configuration in-tact. – Christopher Schultz Apr 18 '18 at 22:48
  • I wonder if the environment variable can be set directly on the service: https://serverfault.com/a/1103091/145894 – VertigoRay Jul 13 '22 at 13:33
1

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

user293755
  • 11
  • 1
0

I faced similar issue with Tomcat 6 and Java 6. (I realize that you are talking about Tomcat 4 and Java 1.4)

I would check in appwiz.cpl whether there is JRE 1.6* installed on the machine - because if it is, then JAVA_HOME is not anymore taken from the environment variables but from the registry entry created by JRE 1.6 installation. (In worst case you can edit %TOMCAT_HOME%/bin/catalina.bat and set JAVA_HOME that points to your good JDK there///)

The relevant link could be

https://issues.apache.org/bugzilla/show_bug.cgi?id=41538

studiohack
  • 305
  • 5
  • 17
Aviad
  • 1