I have the following problem configuring tomcat 7 to run as a service on windows.

More specifically, tomcat is part of a web application which is installed on our customers' servers, and it must have all of its dependencies inside.

In this case, tomcat depends on the Java JDK/JRE, so I downloaded a standalone jdk (version 1.7u21) with its jre and placed it inside the tomcat folder.

So now my directory tree is like this:

  - bin
  - conf
  - jdk
    - jre
  - logs
  - temp
  - webapps
  - work

I then proceeded installing it as a service using the command

tomcat\bin\service.bat install

And it gets installed with no problem, in jvm mode.

Please note that I modified the service.bat file so that all the needed variables are correctly set, that is, CATALINA_HOME, CATALINA_BASE, JAVA_HOME and JRE_HOME, and the last two point to the internal jdk/jre.

However, if I try to start the service, I get an error which says that it is unable to start the service and refers to error code 1.

Looking in the tomcat logs, it says:

[2013-05-22 12:22:09] [info]  [ 5392] Commons Daemon procrun ( 32-bit) started
[2013-05-22 12:22:10] [info]  [ 5392] Running 'AGEws2Tomcat7' Service...
[2013-05-22 12:22:10] [info]  [ 2764] Starting service...
[2013-05-22 12:22:10] [error] [ 2764] %1 is not a valid Win32 application.
[2013-05-22 12:22:10] [error] [ 2764] Failed creating java C:\AGEws\tomcat7\jdk\jre\bin\server\jvm.dll
[2013-05-22 12:22:10] [error] [ 2764] %1 is not a valid Win32 application.
[2013-05-22 12:22:10] [error] [ 2764] ServiceStart returned 1
[2013-05-22 12:22:11] [error] [ 2764] %1 is not a valid Win32 application.
[2013-05-22 12:22:11] [info]  [ 5392] Run service finished.
[2013-05-22 12:22:11] [info]  [ 5392] Commons Daemon procrun finished

I tried googling a bit about the part Failed creating java and I found out some information about a possible dependency on a .dll file, which I have found but I do not understand where should I place it, if this is indeed the problem.

I also tried installing the service in java mode, and it works but uses my computer's own JVM instead of the internal one, while I need it to use the internal one.

What can/must I do in order to have tomcat work properly as a service in jvm mode, using its own jdk/jre?

Please note that our web application used to ship with tomcat 5, which worked perfectly in jvm mode.


In the end I found out that the solutions was to set the start and stop mode to java while at the same time providing an explicit JAVA_HOME with the option

--JavaHome /path/to/internal/jdk

After doing the modification the service works fine, even if in java mode instead of jvm mode as the old service used to.


To clarify on Matteo's answer (and help Windows guys that are not overly familiar with the Java world), we had the exact same issue using Tomcat 8 on 64-bit Windows Server 2012 (non-R2). We were using/configuring IBM Rational DOORS Help 9.6.1 - though we've seen this with most IBM Java/Tomcat-style products when trying to configure on relatively modern 64-bit flavours of Windows.

We had to update the service.bat file located within the Tomcat installation directory with the following:

--StartMode java ^
--StopMode java ^
--JavaHome "C:\Program Files (x86)\Java\jre7" ^

The start/stop options were changing from 'jvm' and the JavaHome option is a new addition to the configuration file. Then you perform the installation of the service via:

service.bat install <service name>

In our case, the service name was DOORS_Help. We had a 64-bit Tomcat install and a 32-bit JRE install which obviously then worked together - it's what was provided by the vendor.

Edit: Another option appears to be manually setting the JRE_HOME and JAVA_HOME environment variables before installing Tomcat. Otherwise you will need to re-install the Windows service. I know this kind of contradicts the original post, but it seems not all Tomcat installs are alike!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.