Pregunta

I am trying to get a Java application to run as a Linux service using jsvc. I found How to convert a java program to daemon with jsvc? which was able to get me most of the way, but I am still struggling to get the classpath figured out.

I am getting the following errors to stderr:

19/04/2013 10:43:18 12233 jsvc.exec error: Cannot find daemon loader org/apache/commons/daemon/support/DaemonLoader

19/04/2013 10:43:18 12231 jsvc.exec error: Service exit with a return value of 1

It would seem that the runtime is unable to find the commons-daemon.jar.

My application is structured so that with the application itself in a single jar file, with dependencies, including commons-daemon in a lib directory.

  • daemon-script.sh
  • myapp.jar
  • lib/commons-daemon.jar
  • lib/other-jars

Here is the relevant parts of my daemon-script.sh:

LIB_DIR=$(pwd)/lib/*

CLASS_PATH=$(pwd)/myapp.jar

$EXEC -home $JAVA_EXEC -cp $CLASS_PATH:$LIB_DIR -outfile $LOG_OUT -errfile $LOG_ERR -pidfile $PID $1 $CLASS

I have tried numerous variations: relative path, specifically referencing lib/commons-daemon.jar, no wildcard, etc. Does anyone have an idea how to make this work properly?

Also, myapp.jar is a self-executable jar (mostly for testing purposes, and yes, I still need it to run as a service), so the manifest.mf contains the Class-Path and Main-Class attributes. Is there a way to get jsvc to recognize the manifest?

¿Fue útil?

Solución

You can use multiple jars with JSVC using : between them.

For your specific issue the solution would be changing the CLASS_PATH variable to this:

CLASS_PATH=$(pwd)/myapp.jar:$(pwd)/lib/commons-daemon.jar:$(pwd)/lib/other-jars

Alternatively you can include all jars in a directory by using wildcards like this:

CLASS_PATH=$(pwd)/myapp.jar:$(pwd)/lib/*.jar

Hope this helps

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top