views:

374

answers:

2

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?

A: 

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"
Rob Heiser
I changed the parameter to --StopMethod="stop" but the same error still shows up in the log. It appears to override the option for --StopMethod and calls "main" instead."[618 javajni.c] [error] Static method 'void main(String[])' in Class com/caphyon/service/JavaService not found"
mcdon
It also looks like the stop() method needs to take a String array as a parameter for it to work.
Rob Heiser
You're right, if I change the method in java to "public static void stop(String[] argv)" it then works correctly. It looks like procrun doesn't like parameterless java functions.
mcdon
A: 

Hi, try to check this example here: http://blog.platinumsolutions.com/node/234

you can find all the details...

andrew007