I installed a standard executable jar file as a Windows service by running the following command:
> prunsrv.exe //IS//"My Service" --Install="C:\path-to-prunsrv.exe" --Jvm=auto \
--Startup=auto --StartMode=jvm --Classpath="C:\path-to-MyService.jar" \
--StartClass=com.mydomain.MyService
I can now run my program fine in console mode by running the following command (I'm using Java 1.6):
> prunsrv.exe //TS//"My Service"
When I try to start the service through the standard Windows services interface, I get the following error message:
The MyService service on Local Computer started and then stopped. Some services stop automatically if they are not in use by other services or programs.
There is no output in my application's log file when I attempt to start the service this way. There is also no output in the Window's event log (Windows 7 64-bit). What can I do to try and figure out why this service will not run?
Don't use any white-space in the service name!
After many hours of testing and pulling apart Tomcat and duplicating it's bootstrap process, the fix for my problem ended up being that Apache Commons Daemon (Procrun) does not work properly when there is white-space in the name of the Windows service.
It seemingly correctly installs and registers a service with Windows when there are spaces in the service name. The Windows registry entries even look correct. The service even runs in debug (aka TS or console) mode just fine. When run, however, as an actual service launched by Windows it fails if the service was installed with a white-space in the service name.
I sure wish Procrun had some type of log output when it fails! Good logging can make debugging issues like this a snap.
I did need to have multiple words in my service name, so I named my service with one word and changed the name with the "DisplayName" parameter:
> prunsrv.exe //IS//MyService --Install="C:\path-to-prunsrv.exe" --Jvm=auto \
--Startup=auto --StartMode=jvm --Classpath="C:\path-to-MyService.jar" \
--StartClass=com.mydomain.MyService --DisplayName="My Service"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With