install a jar with a servicename

196 Views Asked by At

I have to start, stop a jar in a flow 1. I have to stop it if it is already running and then start 2. All this is being worked in Udeploy. 3. I'm installing the jar using the below command. java -jar jarname.jar

When I use sc query servicename, it says the service is not installed as a Windows service. So, I can check, stop and start if it is only a windows service.

How can I install this as a windows service with a servicename to identify ?

1

There are 1 best solutions below

0
On

You can use nssm to install a jar as a Windows service. No installation of nssm is needed. Just place it somewhere on the system (preferably somewhere in your PATH) and run it.

Here is the command to execute as a batch:

nssm.exe install "(service-name)" "{java.exe path from jre}" "-jar {jar-name-absolute-path}"

nssm.exe set "{service-name}" AppDirectory "{jar-path}"