java 服务包装器,非常基本的一步一步设置,启动失败
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/10691914/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
java service wrapper, very basic step by step setup with startup failure
提问by AgostinoX
I have simply donwloaded JSW community edition, unwrapped into a directory: c:\servicetest
So here i have a bin, conf, lib and log subdirs, among others.
From now on this will be (root).
I referenced the (root)/lib/wrapper.jar into my ide (netbeans) and create a very simple service (remember the class name is Main):
我只是简单地下载了 JSW 社区版,解压到一个目录中:c:\servicetest
所以这里我有一个 bin、conf、lib 和 log 子目录,等等。从现在开始,这将是(根)。
我将 (root)/lib/wrapper.jar 引用到我的 ide (netbeans) 中并创建了一个非常简单的服务(记住类名是 Main):
public class Main extends WrapperSimpleApp {
public Main(String[] args) {
super(args);
}
@Override
public void run() {
while(true) {
Logger.getLogger(Main.class.getName()).log(Level.INFO, "I'm alive");
try
{ Thread.sleep(2000); }
catch (InterruptedException ex)
{ return; }
}
}
}
As you see, it basically does nothing but logging a message. But actually it neither starts.
如您所见,它基本上除了记录一条消息之外什么都不做。但实际上它既没有开始。
I compiled the project (MyProject.jar), copied the jar into the (root) directory and modified the (root)/config/wrapper.conf adding:
我编译了项目 (MyProject.jar),将 jar 复制到 (root) 目录并修改 (root)/config/wrapper.conf 添加:
wrapper.java.classpath.3=../MyProject.jar
and
和
wrapper.java.mainclass=textappender.Main
Then i've installed the service in command line, with:
然后我在命令行中安装了该服务,使用:
C:\servicetest\bin>wrapper -i ../conf/wrapper.conf
then i've started the service, either via services.msc control panel or via
然后我通过 services.msc 控制面板或通过
C:\servicetest\bin>wrapper -t ../conf/wrapper.conf
In logs/wrapper.log i get:
在日志/wrapper.log 我得到:
ERROR | wrapper | 2012/05/21 21:35:11 | JVM exited while loading the application.
UPDATE 1
更新 1
Following Tanuki Software advice, i've set in my (root)/config/wrapper.conf (well, uncommented since it already was):
按照 Tanuki Software 的建议,我已经在我的 (root)/config/wrapper.conf 中进行了设置(好吧,因为它已经是取消注释的):
wrapper.debug=TRUE
And now i get this:
现在我明白了:
INFO | jvm 1 | 2012/05/22 10:46:37 | WrapperManager Debug: WrapperManager.stop(1) called by thread: main
INFO | jvm 1 | 2012/05/22 10:46:37 | WrapperManager Debug: Backend not connected, not sending packet STOP : 1
INFO | jvm 1 | 2012/05/22 10:46:37 | WrapperManager Debug: Stopped checking for control events.
DEBUG | wrapper | 2012/05/22 10:46:37 | Pause reading child process output to share cycles.
INFO | jvm 1 | 2012/05/22 10:46:37 | WrapperManager Debug: Thread, main, handling the shutdown process.
INFO | jvm 1 | 2012/05/22 10:46:37 | WrapperManager Debug: shutdownJVM(1) Thread: main
INFO | jvm 1 | 2012/05/22 10:46:38 | WrapperManager Debug: wait for 0 shutdown locks to be released.
INFO | jvm 1 | 2012/05/22 10:46:38 | WrapperManager Debug: Backend not connected, not sending packet STOPPED : 1
INFO | jvm 1 | 2012/05/22 10:46:38 | WrapperManager Debug: calling System.exit(1)
DEBUG | wrapper | 2012/05/22 10:46:38 | JVM process exited with a code of 1, setting the wrapper exit code to 1.
But given my very simple implementation, i cannot guess what is going wrong.
但鉴于我的实现非常简单,我无法猜测出了什么问题。
回答by Naytzyrhc
rather than extending WrapperSimpleApp, your main class should implement the org.tanukisoftware.wrapper.WrapperListener interface.
您的主类应该实现 org.tanukisoftware.wrapper.WrapperListener 接口,而不是扩展 WrapperSimpleApp。
You can find a very detailed description about implementing the interface on our website: http://wrapper.tanukisoftware.com/doc/english/integrate-listener.html
您可以在我们的网站上找到有关实现该接口的非常详细的说明:http: //wrapper.tanukisoftware.com/doc/english/integrate-listener.html
Please let me know if you have any further questions about the implementation and/or the configuration properties in your conf file.
如果您对 conf 文件中的实现和/或配置属性有任何进一步的问题,请告诉我。
Another advise which comes in handy for me sometimes, is rather than running your application immediately as service, I find it easier to do the integration by running first as console application, because you can see the output directly on your console. Once everything seems working, I go ahead and install/run as service. To run as console application, you would run for example:
有时对我有用的另一个建议是,与其将应用程序立即作为服务运行,我发现通过首先作为控制台应用程序运行来进行集成更容易,因为您可以直接在控制台上看到输出。一旦一切正常,我就会继续安装/作为服务运行。要作为控制台应用程序运行,您可以运行例如:
C:\servicetest\bin>wrapper -c ../conf/wrapper.conf
You can also turn on debug output for the Wrapper by setting
您还可以通过设置打开 Wrapper 的调试输出
wrapper.debug=true
in your conf file.
在您的 conf 文件中。
Edit due to the comment:
由于评论而编辑:
if your application is actually as simple as you describe, then just write your application as normal Java application without any Wrapper API parts.
如果您的应用程序实际上像您描述的一样简单,那么只需将您的应用程序编写为普通的 Java 应用程序,无需任何 Wrapper API 部分。
You can use the WrapperSimpleApp to run your application out of the box with codeless integration into the Wrapper.
您可以使用 WrapperSimpleApp 通过无代码集成到 Wrapper 来运行您的应用程序。
All you need to do is set the following properties in your conf file:
您需要做的就是在您的 conf 文件中设置以下属性:
wrapper.java.mainclass=org.tanukisoftware.wrapper.WrapperSimpleApp
wrapper.app.parameter.1=textappender.Main
wrapper.java.classpath.1=../lib/wrapper.jar
wrapper.java.classpath.2=../MyProject.jar
With this configuration, the Wrapper will be able to run your application as windows service.
使用此配置,Wrapper 将能够将您的应用程序作为 Windows 服务运行。
UPDATE2
更新2
I'm not sure what your code exactly looks like, but it seems you are calling WrapperManager.stop() in your main class...
我不确定你的代码到底是什么样子,但你似乎在你的主类中调用 WrapperManager.stop() ......
Following the initial example class, I have modified the class, so it is not using any Wrapper-API (which for an simple application is not necessary):
在最初的示例类之后,我修改了该类,因此它不使用任何 Wrapper-API(对于简单的应用程序不需要):
public class Main {
public static void main(String[] args) {
while(true) {
Logger.getLogger(Main.class.getName()).log(Level.INFO, "I'm alive");
try
{ Thread.sleep(2000); }
catch (java.lang.InterruptedException ex)
{ return; }
}
}
}
After compile and creating the jar, the necessary properties in the conf file are:
编译并创建 jar 后,conf 文件中的必要属性是:
wrapper.java.mainclass=org.tanukisoftware.wrapper.WrapperSimpleApp
wrapper.app.parameter.1=textappender.Main
wrapper.java.classpath.1=../lib/wrapper.jar
wrapper.java.classpath.2=../MyProject.jar
cheers,
干杯,