mcarr
mcarr

Reputation: 121

Installing a Java service on Windows 7 with 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

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?

Upvotes: 10

Views: 17375

Answers (3)

Brad Rippe
Brad Rippe

Reputation: 3515

On Windows 2012 R2 OS, 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

Upvotes: 2

mcarr
mcarr

Reputation: 121

I had to create a powershell script to run the java service:

java.exe -jar service.jar

Then, I reference the full path to powershell in Inno Setup's [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.

Upvotes: 1

rkh
rkh

Reputation: 1791

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:

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

should work. I don't think NSSM searches the path for its application.

Upvotes: 10

Related Questions