将Java JAR作为windows服务运行

将Java JAR作为windows服务运行,java,windows-services,java-service-wrapper,Java,Windows Services,Java Service Wrapper,我有一个可执行的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 cont

我有一个可执行的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服务包装器(Community Edition),该服务会启动一段时间,但每次都会停止。包装器日志的内容如下:

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服务运行,因为我不能在客户端的prod env上使用任何第三方应用程序

如果不是,我需要在Java服务包装器中执行哪些其他配置来启动服务


我试图在stackoverflow上找到一些与此相关的信息,但什么都没有得到。如果任何人对stackoverflow有任何意见,请随时发表评论。

我以前在生产环境中使用过这种方法,因此我可以向您保证使用它是安全的

Jar文件被包装在一个exe中,然后被添加到windows服务调度程序中(或者以您希望的方式调用它)。如果你有一个maven项目,这也是很容易完成的


编辑:你说你不能使用外部软件。使用这种方法,所需的一切都打包在exe文件中。包括JRE,我希望这是您客户的政策允许的

答案存在于下面的链接中。。。已在下面的堆栈溢出问题中回答。。。