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.
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>"
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.