brercia
brercia

Reputation: 211

Implementing JSVC directly without apache-commons-daemon jar

According to the apache commons documentation (https://commons.apache.org/proper/commons-daemon/jsvc.html), I should be able to run my application as a daemon directly using jsvc without implementing the Daemon class:

Directly

Write a Class (MyClass) that implements the following methods:

  • void init(String[] arguments): Here open configuration files, create a trace file, create ServerSockets, Threads
  • void start(): Start the Thread, accept incoming connections
  • void stop(): Inform the Thread to terminate the run(), close the ServerSockets
  • void destroy(): Destroy any object created in init()

Store it in a jarfile and use as above:

./jsvc -cp my.jar MyClass

MyClass implements the above methods, and does not implement the Daemon class. However if I try to invoke jsvc as above without including the commons-daemon.jar in my class path,

I get the following error:

Cannot find the daemon loader org/apache/commons/daemon/support/DaemonLoader
java_init failed

If I include it in the classpath, everything works fine., i.e.

./jsvc -cp commons-daemon.jar:my.jar MyClass

My understanding from the documentation is that I shouldn't need to include the commons-daemon.jar if I'm not using anything from that library, but just invoking jsvc directly on my class with the required methods implemented. Is this incorrect? I don't want to bundle any unnecessary jars with my package.

Upvotes: 0

Views: 858

Answers (1)

Elliott Frisch
Elliott Frisch

Reputation: 201517

I should be able to run my application as a daemon directly using jsvc without implementing the Daemon class Correct.

However if I try to invoke jsvc as above without including the commons-daemon.jar in my class path. Here is where you have gone wrong. You need the commons-daemon.jar, you just aren't implementing Daemon. Apache JSVC still needs it.

Upvotes: 0

Related Questions