I have a JAR file and I would like to register and run it as a Windows service. With a well-configured JAR and already registered JVM shutdown hooks it should not be a big work to do this.
I already have a JAR with external lib
dir, I can start it with java -jar My.jar
and stop with Ctrl+C
.
I also checked JSL, JSmooth, and procrun from Apache with no working solution.
I would need a working solution with a good tutorial.
Update: I succeeded with both procrun (at last), and the manual .net service wrapper too... Here is the code for the procrun version of my install.bat:
set PR_PATH=%CD%
SET PR_SERVICE_NAME=MyService
SET PR_JAR=MyService.jar
SET START_CLASS=org.my.Main
SET START_METHOD=main
SET STOP_CLASS=java.lang.System
SET STOP_METHOD=exit
rem ; separated values
SET STOP_PARAMS=0
rem ; separated values
SET JVM_OPTIONS=-Dapp.home=%PR_PATH%
prunsrv.exe //IS//%PR_SERVICE_NAME% --Install="%PR_PATH%\prunsrv.exe" --Jvm=auto --Startup=auto --StartMode=jvm --StartClass=%START_CLASS% --StartMethod=%START_METHOD% --StopMode=jvm --StopClass=%STOP_CLASS% --StopMethod=%STOP_METHOD% ++StopParams=%STOP_PARAMS% --Classpath="%PR_PATH%\%PR_JAR%" --DisplayName="%PR_SERVICE_NAME%" ++JvmOptions=%JVM_OPTIONS%
I presume to
Thanks to the apache procrun team (http://commons.apache.org/proper/commons-daemon//procrun.html) and to marifnst (http://a089lp.wordpress.com/tag/procrun-tutorial/)
Update 2: a new good tutorial with winsv: https://dzone.com/articles/spring-boot-as-a-windows-service-in-5-minutes
PathToExecutable: Type the full path of the application that you want to run as a Windows service. For example: To install the "Notepad.exe" application as a Windows service with the name "Notepad", give the following command: RunAsService install "Notepad" "C:\Windows\System32\notepad.exe"
Try this java launcher
http://winrun4j.sourceforge.net/
free and open source
start service example at the end of the page
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With