0

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.

Community
  • 1
  • 1
brercia
  • 171
  • 1
  • 6

1 Answers1

0

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.

Elliott Frisch
  • 198,278
  • 20
  • 158
  • 249
  • Is that an error in their documentation? Cause they clearly leave out including the commons-daemon.jar in the example. – brercia Mar 19 '18 at 21:15
  • @brercia Clearly leaving it out does not work. Their documentation may assume you have set the `CLASSPATH` variable. I hesitate to say it's an error, but I suppose *omission* is fair. – Elliott Frisch Mar 19 '18 at 21:38
  • 1
    Thanks for your help. I think I'll post on their mailing list to clarify what they are intending there. I may be mistaken, but believe I have had this working in the past without ever including the jar in the cp. – brercia Mar 19 '18 at 22:10