使用 NSSM 在 Windows 7 上安装 Java 服务
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/31752759/
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
Installing a Java service on Windows 7 with NSSM
提问by mcarr
I am trying to use Inno Setup to install a Windows service as a JAR file running under NSSM (Non-Sucking Service Manager)
我正在尝试使用 Inno Setup 将 Windows 服务安装为在 NSSM(Non-Sucking Service Manager)下运行的 JAR 文件
nssm install JarService java -jar service.jar
nssm start JarService
ends up putting my service in the "Paused" state, and it doesn't ever seem to get started.
最终将我的服务置于“暂停”状态,并且它似乎从未开始。
Since the location of java.exe
can change with updates, I want to be able to run the service without having the explicit path to java.exe
, how can I launch the java service without an explicit path in NSSM?
由于 的位置java.exe
可以随着更新而改变,我希望能够在没有显式路径的情况下运行服务java.exe
,如何在 NSSM 中没有显式路径的情况下启动 java 服务?
采纳答案by rkh
I had to do something quite similar just last week. When I replace "java" with the full path to java.exe, I can get a service to run, so:
就在上周,我不得不做一些非常相似的事情。当我用 java.exe 的完整路径替换“java”时,我可以运行一个服务,所以:
nssm install JarService FullPath/java.exe -jar service.jar
should work. I don't think NSSM searches the path for its application.
应该管用。我认为 NSSM 不会搜索其应用程序的路径。
回答by Brad Rippe
On Windows 2012 R2 OS, I used:
在 Windows 2012 R2 操作系统上,我使用了:
nssm install MyServiceName "C:\Program Files\MyServiceName\start.bat"
Then in the batch file, start.bat, I have:
然后在批处理文件 start.bat 中,我有:
java -cp "C:\Program Files\MyServiceName\MyServiceName.jar" com.package.MyServiceMainClass
回答by mcarr
I had to create a powershell script to run the java service:
我必须创建一个 powershell 脚本来运行 java 服务:
java.exe -jar service.jar
Then, I reference the full path to powershell in Inno Setup's [Run] section:
然后,我在 Inno Setup 的 [Run] 部分中引用了 powershell 的完整路径:
Filename: "{app}\nssm.exe"; Parameters: "install ""{#MyAppName}"" ""{sys}\WindowsPowerShell\v1.0\powershell.exe"" ""-ExecutionPolicy Unrestricted -File {app}\runservice.ps1"""; Flags: runhidden
As long as powershell doesn't move, this should work.
只要powershell不移动,这应该可以工作。