Installing a Java service on Windows 7 with NSSM

14,975

Solution 1

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.

Solution 2

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

Solution 3

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.

Share:
14,975
mcarr
Author by

mcarr

Updated on June 04, 2022

Comments

  • mcarr
    mcarr almost 2 years

    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?

  • Waqas
    Waqas about 4 years
    getting the error when I start the service "windows could not start the service, if its a non Microsoft service refer to service specific error code 3"