I have the class MonitorDaemon which I want to convert to a daemon with jsvc
package com.base.daemon;
import org.apache.commons.daemon.Daemon;
import org.apache.commons.daemon.DaemonContext;
import org.apache.commons.daemon.DaemonInitException;
public class MonitorDaemon implements Daemon {
private Thread myThread;
private boolean stopped = false;
private boolean lastOneWasATick = false;
@Override
public void init(DaemonContext daemonContext) throws DaemonInitException, Exception {
System.out.println("MonitorDaemon init...");
String[] args = daemonContext.getArguments();
myThread = new Thread() {
private long lastTick = 0;
@Override
public synchronized void start() {
MonitorDaemon.this.stopped = false;
super.start();
}
@Override
public void run() {
while (!stopped) {
long now = System.currentTimeMillis();
if (now - lastTick >= 10000) {
System.out.println(!lastOneWasATick ? "tick" : "tock");
lastOneWasATick = !lastOneWasATick;
lastTick = now;
}
try {
Thread.sleep(15000);
} catch (InterruptedException ex) {
//Logger.getLogger(JDaemon.class.getName()).log(Level.SEVERE, null, ex);
}
}
}
};
}
@Override
public void start() throws Exception {
System.out.println("MonitorDaemon start in a Thread...");
myThread.start();
}
@Override
public void stop() throws Exception {
System.out.println("MonitorDaemon stop...");
stopped = true;
try {
myThread.join(1000);
} catch (InterruptedException e) {
System.err.println(e.getMessage());
throw e;
}
}
@Override
public void destroy() {
System.out.println("MonitorDaemon destroy...");
myThread = null;
}
}
Inside /usr/local/monitorFEL/lib/ I have the commons-daemon .jar and inside /usr/local/monitorFEL/ I have the .jar of the class detailed above. Now, when I execute
./jsvc -debug -cp /usr/local/monitorFEL/lib/commons-daemon-1.1.0.jar:/usr/local/monitorFEL/monitorFEL.jar com.base.daemon.MonitorDaemon
I have the next error message
Daemon loading...
java.lang.ClassNotFoundException: com.base.daemon.MonitorDaemon
at java.net.URLClassLoader.findClass(URLClassLoader.java:382)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:349)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
at org.apache.commons.daemon.support.DaemonLoader.load(DaemonLoader.java:148)
Cannot load daemon
java_load failed
Service exit with a return value of 3
Here is the complete result of the debugged instruction
+-- DUMPING PARSED COMMAND LINE ARGUMENTS --------------
| Detach: True
| Show Version: No
| Show Help: No
| Check Only: Disabled
| Stop: False
| Wait: 0
| Run as service: No
| Install service: No
| Remove service: No
| JVM Name: "null"
| Java Home: "null"
| PID File: "/var/run/jsvc.pid"
| User Name: "null"
| Extra Options: 1
| "-Djava.class.path=/usr/local/monitorFEL/lib/commons-daemon-1.1.0.jar:/usr/local/monitorFEL/monitorFEL.jar"
| Class Invoked: "com.base.daemon.MonitorDaemon"
| Class Arguments: 0
+-------------------------------------------------------
Home not specified on command line, using environment
Attempting to locate Java Home in /usr/lib/jvm/java-8-openjdk-amd64
Attempting to locate VM configuration file /usr/lib/jvm/java-8-openjdk-amd64/jre/lib/jvm.cfg
Attempting to locate VM configuration file /usr/lib/jvm/java-8-openjdk-amd64/lib/jvm.cfg
Attempting to locate VM configuration file /usr/lib/jvm/java-8-openjdk-amd64/jre/lib/amd64/jvm.cfg
Found VM configuration file at /usr/lib/jvm/java-8-openjdk-amd64/jre/lib/amd64/jvm.cfg
Found VM server definition in configuration
Checking library /usr/lib/jvm/java-8-openjdk-amd64/jre/lib/amd64/server/libjvm.so
Found VM client definition in configuration
Checking library /usr/lib/jvm/java-8-openjdk-amd64/jre/lib/amd64/client/libjvm.so
Checking library /usr/lib/jvm/java-8-openjdk-amd64/lib/amd64/client/libjvm.so
Cannot locate library for VM client (skipping)
Found VM zero definition in configuration
Checking library /usr/lib/jvm/java-8-openjdk-amd64/jre/lib/amd64/zero/libjvm.so
Checking library /usr/lib/jvm/java-8-openjdk-amd64/lib/amd64/zero/libjvm.so
Cannot locate library for VM zero (skipping)
Found VM dcevm definition in configuration
Checking library /usr/lib/jvm/java-8-openjdk-amd64/jre/lib/amd64/dcevm/libjvm.so
Checking library /usr/lib/jvm/java-8-openjdk-amd64/lib/amd64/dcevm/libjvm.so
Cannot locate library for VM dcevm (skipping)
Java Home located in /usr/lib/jvm/java-8-openjdk-amd64
+-- DUMPING JAVA HOME STRUCTURE ------------------------
| Java Home: "/usr/lib/jvm/java-8-openjdk-amd64"
| Java VM Config.: "/usr/lib/jvm/java-8-openjdk-amd64/jre/lib/amd64/jvm.cfg"
| Found JVMs: 1
| JVM Name: "server"
| "/usr/lib/jvm/java-8-openjdk-amd64/jre/lib/amd64/server/libjvm.so"
+-------------------------------------------------------
Using default JVM in /usr/lib/jvm/java-8-openjdk-amd64/jre/lib/amd64/server/libjvm.so
Invoking w/ LD_LIBRARY_PATH=/usr/lib/jvm/java-8-openjdk-amd64/jre/lib/amd64/server:/usr/lib/jvm/java-8-openjdk-amd64/jre/lib/amd64
+-- DUMPING PARSED COMMAND LINE ARGUMENTS --------------
| Detach: True
| Show Version: No
| Show Help: No
| Check Only: Disabled
| Stop: False
| Wait: 0
| Run as service: No
| Install service: No
| Remove service: No
| JVM Name: "null"
| Java Home: "null"
| PID File: "/var/run/jsvc.pid"
| User Name: "null"
| Extra Options: 1
| "-Djava.class.path=/usr/local/monitorFEL/lib/commons-daemon-1.1.0.jar:/usr/local/monitorFEL/monitorFEL.jar"
| Class Invoked: "com.base.daemon.MonitorDaemon"
| Class Arguments: 0
+-------------------------------------------------------
Home not specified on command line, using environment
Attempting to locate Java Home in /usr/lib/jvm/java-8-openjdk-amd64
Attempting to locate VM configuration file /usr/lib/jvm/java-8-openjdk-amd64/jre/lib/jvm.cfg
Attempting to locate VM configuration file /usr/lib/jvm/java-8-openjdk-amd64/lib/jvm.cfg
Attempting to locate VM configuration file /usr/lib/jvm/java-8-openjdk-amd64/jre/lib/amd64/jvm.cfg
Found VM configuration file at /usr/lib/jvm/java-8-openjdk-amd64/jre/lib/amd64/jvm.cfg
Found VM server definition in configuration
Checking library /usr/lib/jvm/java-8-openjdk-amd64/jre/lib/amd64/server/libjvm.so
Found VM client definition in configuration
Checking library /usr/lib/jvm/java-8-openjdk-amd64/jre/lib/amd64/client/libjvm.so
Checking library /usr/lib/jvm/java-8-openjdk-amd64/lib/amd64/client/libjvm.so
Cannot locate library for VM client (skipping)
Found VM zero definition in configuration
Checking library /usr/lib/jvm/java-8-openjdk-amd64/jre/lib/amd64/zero/libjvm.so
Checking library /usr/lib/jvm/java-8-openjdk-amd64/lib/amd64/zero/libjvm.so
Cannot locate library for VM zero (skipping)
Found VM dcevm definition in configuration
Checking library /usr/lib/jvm/java-8-openjdk-amd64/jre/lib/amd64/dcevm/libjvm.so
Checking library /usr/lib/jvm/java-8-openjdk-amd64/lib/amd64/dcevm/libjvm.so
Cannot locate library for VM dcevm (skipping)
Java Home located in /usr/lib/jvm/java-8-openjdk-amd64
+-- DUMPING JAVA HOME STRUCTURE ------------------------
| Java Home: "/usr/lib/jvm/java-8-openjdk-amd64"
| Java VM Config.: "/usr/lib/jvm/java-8-openjdk-amd64/jre/lib/amd64/jvm.cfg"
| Found JVMs: 1
| JVM Name: "server"
| "/usr/lib/jvm/java-8-openjdk-amd64/jre/lib/amd64/server/libjvm.so"
+-------------------------------------------------------
Running w/ LD_LIBRARY_PATH=/usr/lib/jvm/java-8-openjdk-amd64/jre/lib/amd64/server:/usr/lib/jvm/java-8-openjdk-amd64/jre/lib/amd64
redirecting stdout to /dev/null and stderr to /dev/null
Switching umask back to 022 from 077
Using default JVM in /usr/lib/jvm/java-8-openjdk-amd64/jre/lib/amd64/server/libjvm.so
Attemtping to load library /usr/lib/jvm/java-8-openjdk-amd64/jre/lib/amd64/server/libjvm.so
morris@morris-ThinkPad-E470:/usr/bin$ JVM library /usr/lib/jvm/java-8-openjdk-amd64/jre/lib/amd64/server/libjvm.so loaded
JVM library entry point found (0xC5F62F90)
+-- DUMPING JAVA VM CREATION ARGUMENTS -----------------
| Version: 0x010004
| Ignore Unrecognized Arguments: True
| Extra options: 1
| "-Djava.class.path=/usr/local/monitorFEL/lib/commons-daemon-1.1.0.jar:/usr/local/monitorFEL/monitorFEL.jar" (0x00000000)
+-------------------------------------------------------
| Internal options: 4
| "-Dcommons.daemon.process.id=23091" (0x00000000)
| "-Dcommons.daemon.process.parent=23090" (0x00000000)
| "-Dcommons.daemon.version=1.0.15-dev" (0x00000000)
| "abort" (0x00405af0)
+-------------------------------------------------------
Java VM created successfully
Class org/apache/commons/daemon/support/DaemonLoader found
Native methods registered
java_init done
Daemon loading...
java.lang.ClassNotFoundException: com.base.daemon.MonitorDaemon
at java.net.URLClassLoader.findClass(URLClassLoader.java:382)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:349)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
at org.apache.commons.daemon.support.DaemonLoader.load(DaemonLoader.java:148)
Cannot load daemon
java_load failed
Service exit with a return value of 3
Please, can anybody help me to solve this error?