It seems that with Java 6.0 the Tomcat Windows Service Installer just doesn't do what its name implies: it always fails to start Tomcat as a Windows Service. Unless you go and fix things manually.
I wanted to test how Tomcat 6.0 can be installed to run automatically as a Windows service, to make life easy for Windows users. I downloaded the Tomcat Windows Service Installer (apache-tomcat-6.0.18.exe), which I used successfully in the past. The installation went fine, except that the service then just refused to start. A minor detail.
The Windows error message was very helpful as usual:
C:\>net start "Apache Tomcat" The Apache Tomcat service is starting. The Apache Tomcat service could not be started. A service specific error occurred: 0. More help is available by typing NET HELPMSG 3547. C:\>net helpmsg 3547 A service specific error occurred: ***. EXPLANATION A service-specific error occurred. ACTION Refer to the Help or documentation for that service to determine the problem.
The Tomcat logs thankfully provided some more details - at least a search string to google for:
[2009-05-30 02:52:27] [info] Starting service... [2009-05-30 02:52:28] [174 javajni.c] [error] The specified module could not be found. [2009-05-30 02:52:28] [994 prunsrv.c] [error] Failed creating java C:\Program Files\Java\jdk1.6.0_13\jre\bin\server\jvm.dll [2009-05-30 02:52:28] [1269 prunsrv.c] [error] ServiceStart returned 1
Java SE 6 applications that use custom launchers must be installed with msvcr71.dll in the same directory as the launcher executable. This follows the new Windows C runtime distribution model, per http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vclib/html/_CRT_C_Run.2d.Time_Libraries.asp.
Tomcat apparently didn't want to take responsibility for the issue either - Bug 41538 has been closed as WORKSFORME. So we're left in this situation where using the latest Java version and the latest Tomcat Windows installer, the Service just doesn't start unless you go and manually perform an obscure additional step. Not exactly what an automated installer is meant for.
One way to fix the problem is to copy this msvcr71.dll from the Java bin directory to the Tomcat bin directory. That's basically what Sun is saying, and most other people seem to suggest as well (e.g. Atlassian Confluence).
However I think there's at least another - possibly better - option, and that's why I'm writing this blog entry. (EDIT: This is also mentioned by Mladen Turk in the Tomcat bug report, although I only noticed this later.) The missing DLL will be found if it simply is in the PATH. In other words, setting PATH=%PATH%;%JAVA_HOME%\bin (assuming you've also set JAVA_HOME appropriately) will also work, and it doesn't involve copying files around.
Ideally I'd like to find a way to set a custom PATH only for starting the Tomcat service, and have the Tomcat installer take care of that, but I'm not quite there yet. However, setting the PATH globally in My Computer / Advanced / Environment Variables certainly does the trick.
UPDATE: changing the Working Path to C:\Program Files\Java\jre6\bin directly in the Tomcat Service configuration also seems to work, without modifying the PATH nor copying msvcr71.dll, and it's something that could be done automatically by the installer.