How to wrap your java backend app as a Window service?

How to wrap your java backend app as a Window service?
Photo by Nathan Fertig / Unsplash
Procrun is a set of applications that allow Windows users to wrap (mostly) Java applications (e.g. Tomcat) as a Windows service.

Bundle below Power Shell(ps1) files into your app's jar file

InstallYourService.ps1

.\prunsrv.exe //IS//YourService --DisplayName="YourService" --Description="YourService" --Startup=auto --Install="c:\Program Files\yourservice\bin\prunsrv.exe"  --Jvm="c:\Program Files\yourjvm\jvm.dll" --Classpath="c:\Program Files\yourservice\lib\yourserver-xx.x.jar"  --StartMode=jvm --StartClass=com.yourservice.SpringBootApplication --StartMethod=main --StartParams=start --StopMode=jvm --StopClass=com.yourservice.SpringBootApplication  --StopMethod=stop --StopParams=stop --StdOutput=auto  --StdError=auto --LogPath="c:\Program Files\yourservice\log" --LogLevel=Debug --JvmOptions="-Dxx=yy"

Once you run the above install power shell script, you will be able to see your java app registered as a service in "Services" manager panel. Then you can stop or restart the service at your own.

References

Daemon – Daemon : Procrun

Subscribe to Post, Code and Quiet Time.

Don’t miss out on the latest issues. Sign up now to get access to the library of members-only issues.
jamie@example.com
Subscribe