Install java service on Windows 7 using NSSM

I am trying to use Inno Setup to install a Windows service as a jar file running under NSSM (Non-Sucking Service Manager)

nssm install JarService java -jar service.jar nssm start JarService

it ends up with my service being in a paused state and it never starts.

Since the location of java.exe can change with updates, I want to be able to start the service without having an explicit path to java.exe, how can I start a Java service without an explicit path in NSSM?

+7
java windows-services inno-setup nssm
source share
3 answers

I needed to do something very similar last week. When I replace "java" with the full path to java.exe, I can start the service to:

 nssm install JarService FullPath/java.exe -jar service.jar 

must work. I do not think NSSM is looking for a way for its application.

+7
source share

I needed to create a powershell script to start the java service:

 java.exe -jar service.jar 

Then I refer to the full path to powershell in the Inno Setup [Run] section:

 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.

+1
source share

In Windows 2012 R2, I used:

 nssm install MyServiceName "C:\Program Files\MyServiceName\start.bat" 

Then in the batch file start.bat I have:

 java -cp "C:\Program Files\MyServiceName\MyServiceName.jar" com.package.MyServiceMainClass 
+1
source share

All Articles