我有一个可执行的 jar,我试图使用 sc.exe 创建一个 Windows 服务。我使用以下代码创建服务:
sc create "TestService" binPath= "C:\Program Files\Java\jdk1.6.0_03\jre\bin\java.exe -jar C:\abc\MainClass.jar"
该服务已创建,但是当我尝试启动该服务时,出现以下错误:
Error 1053: The service did not respond to the start or control request in a timely fashion.
后来我尝试使用Java Service Wrapper(社区版),该服务启动了一段时间但每次都停止了。包装器日志告诉类似:
Advice:
The Wrapper consists of a native component as well as a set of classes
which run within the JVM that it launches. The Java component of the
Wrapper must be initialized promptly after the JVM is launched or the
Wrapper will timeout, as just happened. Most likely the main class
specified in the Wrapper configuration file is not correctly initializing
the Wrapper classes:
com.MainClass
While it is possible to do so manually, the Wrapper ships with helper
classes to make this initialization processes automatic.
Please review the integration section of the Wrapper's documentation
for the various methods which can be employed to launch an application
within the Wrapper
谁能告诉我如何在不使用外部软件的情况下将 jar 作为 Windows 服务运行,因为我不能在客户的产品环境中使用任何第三方应用程序。
如果不是我需要在 Java Service Wrapper 中进行的其他配置以使服务启动。
我试图在stackoverflow上找到一些与此相关的信息,但我没有得到任何东西。如果有人对 stackoverflow 有任何意见,请随时发表评论。