Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to create windows service from java jar?

I have an executable JAR file. Is it possible to create a Windows service of that JAR? Actually, I just want to run that on startup, but I don't want to place that JAR file in my startup folder, neither in the registry.

like image 461
Rakesh Juyal Avatar asked Oct 24 '09 09:10

Rakesh Juyal


2 Answers

The easiest solution I found for this so far is the Non-Sucking Service Manager

Usage would be

nssm install <servicename> "C:\Program Files\Java\jre7\java.exe" "-jar <path-to-jar-file>" 
like image 126
kopernik Avatar answered Oct 04 '22 12:10

kopernik


Use nssm.exe but remember to set the AppDirectory or any required libraries or resources will not be accessible. By default nssm set the current working directory to the that of the application, java.exe, not the jar. So do this to create a batch script:

    pushd <path-to-jar>     nssm.exe install "<service-name>" "<path-to-java.exe>" "-jar <name-of-jar>"     nssm.exe set "<service-name>" AppDirectory "<path-to-jar>" 

This should fix the service paused issue.

like image 43
gcerkez Avatar answered Oct 04 '22 11:10

gcerkez