title: Spring boot JAR as windows service
body: <p>I am trying to wrap a spring boot "uber JAR" with procrun. </p>
  
  <p>Running the following works as expected:</p>
  
  <blockquote>
    <p>java -jar my.jar</p>
  </blockquote>
  
  <p>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).</p>
  
  <p>When I try to run this I am getting "Commons Daemon procrun failed with exit value: 3"</p>
  
  <p>Looking at the spring-boot source it looks as if it uses a custom classloader: </p>
  
  <blockquote>
    <p><a href="https://github.com/spring-projects/spring-boot/blob/master/spring-boot-tools/spring-boot-loader/src/main/java/org/springframework/boot/loader/JarLauncher.java">https://github.com/spring-projects/spring-boot/blob/master/spring-boot-tools/spring-boot-loader/src/main/java/org/springframework/boot/loader/JarLauncher.java</a></p>
  </blockquote>
  
  <p>I also get a "ClassNotFoundException" when trying to run my main method directly.</p>
  
  <blockquote>
    <p>java -cp my.jar my.MainClass</p>
  </blockquote>
  
  <p>Is there a method I can use to run my main method in a spring boot jar (not via JarLauncher)?</p>
  
  <p>Has anyone successfully integrated spring-boot with procrun? </p>
  
  <p>I am aware of <a href="http://wrapper.tanukisoftware.com/">http://wrapper.tanukisoftware.com/</a>. However due to their licence I can't use it. </p>
  
  <p><strong>UPDATE</strong></p>
  
  <p>I have now managed to start the service using procrun.</p>
  
  <pre><code>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%
  </code></pre>
  
  <p>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.</p>
  
  <p>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).</p>