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?

4

There are 4 answers

0
11101101b On BEST ANSWER

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"
1
Suzanne On

I wanted to give some additional information about what '11101101b' said above. (This is my first post, so please be gentle!)

I was able to get the service to install correctly with spaces in the service name by changing the //IS//MyService part of his command to instead be the following, which I suspect is what he also did. (I apologize if I'm assuming incorrectly.) Notice that the opening double quote is at the beginning of the string rather than at the beginning of the service name.

"//IS//My Service"

As was the case for him, the service installed correctly and looked correct, but it wouldn't start. I was able to get around that by changing the service's ImagePath value data setting in the registry to have the same change for the //RS//My Service part of the command. Therefore, the registry value instead had the following in its data setting:

"//RS//My Service"

Everything seems to be working without any problems.

0
Anandh On

This server starts and stops because of reason the task is completed by the service so it would stop automatically. if you have a logic of running long inside it would not stop.

0
Lorenzo Dimitri Bono On

I got same problem ... under my local machine everthing working fine on server the same issue => problem was that Working Path was not set. May its heps someone ... be the force with you

enter image description here