我正在尝试使用JSVC作为守护进程运行java程序。这是我使用过的简单代码:
package daemonexample;
public class DaemonExample implements Daemon {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
// TODO code application logic here
}
@Override
public void init(DaemonContext dc) throws DaemonInitException, Exception {
System.out.println("initializing ...");
}
@Override
public void start() throws Exception {
System.out.println("starting ...");
}
@Override
public void stop() throws Exception {
System.out.println("stopping ...");
}
@Override
public void destroy() {
System.out.println("done.");
}
}
命令:jsvc -debug -home $ JAVA_HOME -cp /path/to/commons-daemon.jar:/path/to/DaemonExample.jar -user coder -outfile /tmp/example.out -errfile / tmp /example.err -pidfile /tmp/example.pid daemonexample.DaemonExample
当我运行它时,我得到:“将stdout重定向到/tmp/example.out并将stderr重定向到/tmp/example.err”。但是目标文件是空的。我在这里缺少什么?
答案 0 :(得分:0)
结帐你的/tmp/example.err。它应包含错误详细信息。
以下可能是问题:
1: you forgot import org.apache.commons.daemon.*; ?
2: if yes, then DaemonExample.class is not getting created.
3: make sure DaemonExample.class exists in DaemonExample.jar
4: jsvc, usually must be called using full path. i.e. /usr/bin/jsvc .... check your debug info
答案 1 :(得分:-2)
无需将用户更改为“root”! 用户'root'已经过验证 未在命令行上指定主页,使用环境 主页不在命令行或环境中,搜索 试图在/System/Library/Frameworks/JavaVM.framework/Home中找到Java Home 试图找到VM配置文件/System/Library/Frameworks/JavaVM.framework/Home/jre/lib/jvm.cfg 试图找到VM配置文件/System/Library/Frameworks/JavaVM.framework/Home/lib/jvm.cfg 在/System/Library/Frameworks/JavaVM.framework/Home/lib/jvm.cfg找到VM配置文件 在配置中找到VM客户端定义 检查库/System/Library/Frameworks/JavaVM.framework/Home/../Libraries/libclient.dylib 在配置中找到VM jvm定义 检查库/System/Library/Frameworks/JavaVM.framework/Home/../Libraries/libjvm.dylib 在配置中找到VM热点定义 检查库/System/Library/Frameworks/JavaVM.framework/Home/../Libraries/libhotspot.dylib 在配置中找到VM服务器定义 检查库/System/Library/Frameworks/JavaVM.framework/Home/../Libraries/libserver.dylib 在配置中找到VM经典定义 检查库/System/Library/Frameworks/JavaVM.framework/Home/../Libraries/libclassic.dylib 无法找到VM经典的库(跳过) Java Home位于/System/Library/Frameworks/JavaVM.framework/Home 倾倒爪哇家居结构 | Java Home:“/ System / Library / Frameworks / JavaVM.framework / Home” | Java VM配置:“/ System / Library / Frameworks / JavaV.framework / Home / lib / jvm.cfg” |找到JVM:4 | JVM名称:“客户端” | “/System/Library/Frameworks/JavaVM.framework/Home/../Libraries/libclient.dylib” | JVM名称:“jvm” | “/System/Library/Frameworks/JavaVM.framework/Home/../Libraries/libjvm.dylib” | JVM名称:“hotspot” | “/System/Library/Frameworks/JavaVM.framework/Home/../Libraries/libhotspot.dylib” | JVM名称:“服务器” | “/System/Library/Frameworks/JavaVM.framework/Home /../库/ libserver.dylib”
将stdout重定向到/tmp/example.out并将stderr重定向到/tmp/example.err