2

I am trying to create a windows service for Apache tomcat 7.0.45. ( in windows version 7)

I executed this :

C:/tomcat7/bin> service install Mytomcat7

Windows service has been created. but it wont start and throws "specific server error code 4".

Can you please help with the steps to create windows service.

janos
  • 120,954
  • 29
  • 226
  • 236
selson
  • 99
  • 2
  • 3
  • 11
  • got to tomcat\logs and post what the commons-daemon.log says – Yazan Jaber Jan 13 '14 at 20:31
  • I dont find commons-daemon.log. I have localhost.log, Catalina.log, manager../log – selson Jan 13 '14 at 21:32
  • This question appears to be off-topic because it is not about programming. Perhaps [Super User](http://superuser.com/) or [Server Fault](http://serverfault.com/) would be a better place to ask. – jww Jun 18 '14 at 03:50

3 Answers3

14

I had the same problem!

Found out, that the service.bat didn't configure the service the right way. If you enable the logging from your service starter:

Log Config

Then you'll see in your loggs something like:

[2014-02-19 16:40:35] [error] ( javajni.c:863 ) [ 2636] FindClass org/apache/catalina/startup/Bootstrap failed
[2014-02-19 16:40:35] [debug] ( javajni.c:964 ) [ 2636] Java Worker thread finished org/apache/catalina/startup/Bootstrap:main with status=3
[2014-02-19 16:40:35] [error] ( prunsrv.c:1183) [ 5000] Failed to start Java
[2014-02-19 16:40:35] [error] ( prunsrv.c:1536) [ 5000] ServiceStart returned 4

You'll notice that there is some classpath problem with the starter. In fact that's the problem! Your service.bat didn't configure the service the right way:

Java Config

Note: You can also choose "Use default" above "Java Virtual Machine" to use whatever JVM is defined in JAVA_HOME

You'll need to set the classpath correctly:

c:\webclient\apache-tomcat\bin\tomcat-juli.jar;c:\webclient\apache-tomcat\bin\tomcat-juli.jar;c:\webclient\apache-tomcat\bin\bootstrap.jar

In my case i "installed" tomcat at: c:\webclient\apache-tomcat replace that part with yours. In my case not even the Java VM was set.. I'm not shure whether this is a problem with the current versions of tomcat (and it's service.bat), or with some sort of permission problem on the windows server itself..

Andrew Tobilko
  • 48,120
  • 14
  • 91
  • 142
Dudelilama
  • 409
  • 4
  • 15
7

To solve this error perform the following steps:

  • Run the tomcat7w.exe monitor application found in <TOMCAT_HOME>/bin.
    Tomcat7w is a GUI application for monitoring and configuring Tomcat services.
    If you named your service Mytomcat7 you will need to rename this file to Mytomcat7.exe before running it
  • In the "Startup" tab change the value of "Mode" from jvm to Java
  • Do the same in the "Shutdown" tab
Dror Bereznitsky
  • 20,048
  • 3
  • 48
  • 57
  • I am getting some file missing error when i use installer. But defentely, I would like to use installer when I start doing the deployment on the production servers. For now, I want to fix this issue in my local. So I have followed the above steps (•Run the tomcat7w.exe ...etc.). Now I am getting a new error code 1. – selson Jan 13 '14 at 23:25
  • Do you see anything in the tomcat logs? should be an error about failing to start the JVM – Dror Bereznitsky Jan 14 '14 at 07:45
  • How is this supposed to help? Am I supposed to see debug information? Where? I've followed these steps, and Tomcat still does not start, and I do not receive any additional information that might help me solve the issue. – liltitus27 Feb 06 '14 at 17:51
  • @liltitus27 you may see an error message in the logs. what type of error are you getting when tomcat fails to start? if this is not the same case, maybe you start a new question – Dror Bereznitsky Feb 10 '14 at 06:54
  • 1
    This was very helpful when pointing out that the exe needed to be renamed to match the name of the service that is installed but failing to start – ununiform Dec 15 '14 at 21:40
2

The easiest way to setup a tomcat Windows service is to use the Tomcat Windows Service Installer found on the same page as tomcat downloads.

http://tomcat.apache.org/download-70.cgi

However, if you are unable to use this installer. Then you can as you have try the above. The service created 'Mytomcat7' can be managed by the tomcat7w.exe file, after you rename it to 'Mytomcat7w.exe'.

Run the renamed file and you will be able to see all options for the service. The error you are seeing is likely related to an invalid JVM location or JVM mode not set to auto. Details of settings found here: http://tomcat.apache.org/tomcat-7.0-doc/windows-service-howto.html

I would just use the installer, it will make your life easier. http://mirror.ox.ac.uk/sites/rsync.apache.org/tomcat/tomcat-7/v7.0.50/bin/apache-tomcat-7.0.50.exe

JayTee
  • 1,209
  • 9
  • 15