windows 如何将 Java 应用程序安装为服务

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/7352291/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-15 18:02:09  来源:igfitidea点击:

How to install a Java application as a service

javawindowsservicejava-service-wrapper

提问by ewok

I have a Java Application written that forwards selected files to an ssh server. I want this application to be automatically run every time windows starts.

我编写了一个 Java 应用程序,可以将选定的文件转发到 ssh 服务器。我希望这个应用程序在每次 Windows 启动时自动运行。

I am aware that this question has been asked multiple times, and I have followed those leads. I have tried Java Service Wrapper (which is no longer accessible because of a dns problem), Apache Daemon, and JSL. Though I have at times been able to get the application installed as a service, I have never been able to get it to run properly on boot, or even start it manually from the command line.

我知道这个问题已经被问过多次,我已经遵循了这些线索。我尝试过 Java Service Wrapper(由于 dns 问题而无法再访问)、Apache Daemon 和 JSL。虽然我有时能够将应用程序安装为服务,但我一直无法让它在启动时正常运行,甚至无法从命令行手动启动它。

My question is whether anyone is aware of a full first step through final step tutorial of how to make this work. I have come across a few things, but they all either assume that you have implemented something that they do not explain how to implement, or rely on applications that I do not have installed.

我的问题是是否有人知道如何完成这项工作的最后一步教程的完整第一步。我遇到了一些事情,但他们要么假设你已经实现了一些他们没有解释如何实现的东西,要么依赖于我没有安装的应用程序。

Thanks

谢谢

回答by Sérgio Michels

I use Java Service Wrapper to install as windows or linux service: http://wrapper.tanukisoftware.com/doc/english/download.jsp

我使用 Java Service Wrapper 安装为 windows 或 linux 服务:http: //wrapper.tanukisoftware.com/doc/english/download.jsp

~> create one runnable JAR to your app.

~> 为您的应用程序创建一个可运行的 JAR。

~> Download the proper service wrapper (they are diffrent to windows and linux)

~> 下载适当的服务包装器(它们与 windows 和 linux 不同)

~> Configure the service in wrapper.conf

~> 在 wrapper.conf 中配置服务

Important: set wrapper.java.classpathcorrect (your jar must be here too) Set wrapper.java.mainclasswith org.tanukisoftware.wrapper.WrapperSimpleApp
Set wrapper.app.parameter.1with the name of your main class, for example:

重要提示:设置wrapper.java.classpath正确(你的 jar 也必须在这里)wrapper.java.mainclassorg.tanukisoftware.wrapper.WrapperSimpleApp
Set 设置wrapper.app.parameter.1你的主类的名称,例如:

wrapper.app.parameter.1=Main

~> Test the service as console (windows bat)

~> 作为控制台测试服务(windows bat)