Spring boot JAR as windows service
Posted
by
roblovelock
on Stack Overflow
See other posts from Stack Overflow
or by roblovelock
Published on 2014-06-09T15:58:26Z
Indexed on
2014/06/12
9:25 UTC
Read the original article
Hit count: 3468
spring-boot
|procrun
I am trying to wrap a spring boot "uber JAR" with procrun.
Running the following works as expected:
java -jar my.jar
I need my spring boot jar to automatically start on windows boot. The nicest solution for this would be to run the jar as a service (same as a standalone tomcat).
When I try to run this I am getting "Commons Daemon procrun failed with exit value: 3"
Looking at the spring-boot source it looks as if it uses a custom classloader:
I also get a "ClassNotFoundException" when trying to run my main method directly.
java -cp my.jar my.MainClass
Is there a method I can use to run my main method in a spring boot jar (not via JarLauncher)?
Has anyone successfully integrated spring-boot with procrun?
I am aware of http://wrapper.tanukisoftware.com/. However due to their licence I can't use it.
UPDATE
I have now managed to start the service using procrun.
set SERVICE_NAME=MyService
set BASE_DIR=C:\MyService\Path
set PR_INSTALL=%BASE_DIR%prunsrv.exe
REM Service log configuration
set PR_LOGPREFIX=%SERVICE_NAME%
set PR_LOGPATH=%BASE_DIR%
set PR_STDOUTPUT=%BASE_DIR%stdout.txt
set PR_STDERROR=%BASE_DIR%stderr.txt
set PR_LOGLEVEL=Error
REM Path to java installation
set PR_JVM=auto
set PR_CLASSPATH=%BASE_DIR%%SERVICE_NAME%.jar
REM Startup configuration
set PR_STARTUP=auto
set PR_STARTIMAGE=c:\Program Files\Java\jre7\bin\java.exe
set PR_STARTMODE=exe
set PR_STARTPARAMS=-jar#%PR_CLASSPATH%
REM Shutdown configuration
set PR_STOPMODE=java
set PR_STOPCLASS=TODO
set PR_STOPMETHOD=stop
REM JVM configuration
set PR_JVMMS=64
set PR_JVMMX=256
REM Install service
%PR_INSTALL% //IS//%SERVICE_NAME%
I now just need to workout how to stop the service. I am thinking of doing someting with the spring-boot actuator shutdown JMX Bean.
What happens when I stop the service at the moment is; windows fails to stop the service (but marks it as stopped), the service is still running (I can browse to localhost), There is no mention of the process in task manager (Not very good! unless I am being blind).
© Stack Overflow or respective owner