You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@commons.apache.org by Rob Tanner <ca...@gmail.com> on 2014/04/22 19:01:33 UTC
Having a problem with jsvc not finding my java class
I’m trying to daemonize a java class that’s doing some mail routing and built jsvc for that purpose. The source I used is from the commons-daemon-1.0.15-src downloaded from the Apache site, and I’m presuming that it’s good code. I grabbed a Linux style start/stop script off the web and modified it for my path and class, etc (shown below). When I run in debug, I can clearly tell that jsvc finds the commons daemon. But, it can’t find my class included in eMailRouter.jar. As far as I can tell, I have the path to the class correct and I tested it by calling from Java rather than jsvc using this command:
java -cp /usr/share/java/commons-daemon-1.0.15.jar:/home/rtanner/Java/Workspace/eMailRouter/eMailRouter.jar org.linfield.eMailRouter.RouterDaemon
Since I added an otherwise unnecessary main method that simply prints out “I’m in main”, I was able to confirm that I had found and executed the class file. My class implements Daemon and at this point really does nothing more (each of the required methods simply print out their name). So is it possible that my problem could be the class itself rather than the start/stop script. Would it help if I posted the Java source for the class?
Immediately below is the start/stop script:
#!/bin/sh
# Setup variables
EXEC=/usr/local/bin/jsvc
export JAVA_HOME=/usr/java/jdk1.7.0_55
export CLASS_PATH=/usr/share/java/commons-daemon-1.0.15.jar:/home/rtanner/Java/Workspace/eMailRouter/eMailRouter.jar
CLASS=org.linfield.eMailRouter.RouterDaemon
USER=root
PID=/tmp/example.pid
LOG_OUT=/tmp/example.out
LOG_ERR=/tmp/example.err
do_exec()
{
$EXEC -debug -home $JAVA_HOME -cp $CLASS_PATH -user $USER -outfile $LOG_OUT -errfile $LOG_ERR -pidfile $PID $1 $CLASS
}
pwd
echo $CLASS_PATH
echo $JAVA_HOME
case "$1" in
start)
do_exec
;;
stop)
do_exec "-stop"
;;
restart)
if [ -f $PID ]; then
do_exec "-stop"
do_exec
else
echo "service not running, will do nothing"
#exit 1
fi
;;
*)
echo $"usage: daemon {start|stop|restart}" #>&2
exit 3
## ;;
esac
exit
Thanks.
~ Rob