Java Windows Service with Procrun, StopMethod problem

javaprocrunwindows-services

My Java class contains the following methods:

public static void main(String[] argv) //start the service

public static void stop() //stop the service

I'm using Procrun from Apache Commons Daemon to setup the Java class as a Windows Service. I get an error when I try to stop the service "[618 javajni.c] [error] Static method 'void main(String[])' in Class com/caphyon/service/JavaService not found". The problem is I am trying to call the stop method when the service is shutting down, but it appears to override the StopMethod with 'void main(String[])'. Here are the stop and start parameters I am using when setting up the service:

prunsrv.exe //US//JavaService –StartClass=com.caphyon.service.JavaService –StartMode=jvm –StartPath="C:\JavaService"

prunsrv.exe //US//JavaService –StopClass=com.caphyon.service.JavaService –StopMode=jvm –StopPath="C:\JavaService" –StopMethod="void stop()"

How do I set the StopMethod prunsrv will call when shutting down the service?

Best Answer

You shouldn't put the return type (i.e., "void") or the parens in the --StopMethod parameter's value. So, the command should be:

prunsrv.exe //US//JavaService --StopClass=com.caphyon.service.JavaService --StopMode=jvm --StopPath="C:\JavaService" --StopMethod="stop"