Running Jetty 8.1 as a Windows Service

Filed under: Java — lars @ 03:30:35 pm

Today I set up Jetty 8.1.3 to run as a Windows service. It wasn't was easy as it should be, I found a Jetty 7 example and a bit of trial and error was required - so I wanted to write up what I did.

  1. I assume you've got a working jetty install that will work if you run the below from c:\jetty\jetty-distribution-8.1.3.v20120416:
    java -jar start.jar
  2. Download the Windows binary for Apache procrun (should be available from here). The file you want is called prunsrv.exe, which you should copy in to c:\jetty\jetty-distribution-8.1.3.v20120416\.

  3. I created the following script called "create_jetty_service.bat":
    prunsrv //IS//JettyService --DisplayName="Jetty v8.1.3 Service" --Startup=auto
    --StartMode=java --StopMode=java --Classpath=C:\jetty\jetty-distribution-8.1.3.v20120416\start.jar
    --StartClass=org.eclipse.jetty.start.Main --StopClass=org.eclipse.jetty.start.Main
    (Note - when creating this .bat file, the above should all be on one line!)

    This script should be saved in c:\jetty\jetty-distribution-8.1.3.v20120416 and run from there. It uses a hard-coded path to specify jetty.home and the location of start.jar. With jetty.home specified, the settings from start.ini should then be used when you start the service. The script assumes java is installed, and according to the docs, the JAVA_HOME environment variable must be set.

    The start-up of the service is set to be automatic by the script, but you can change this from the Windows control panel too.

  4. Once you've run the above create script, you can test the start-up of the service using this command:
    prunsrv.exe //TS//JettyService
  5. You can also delete the service using this command (necessary if you want to re-create it with different options).
    prunsrv.exe //DS//JettyService

I hope this helps someone out there.


  • dave
    Thanks, very useful.

    Comment by dave [Visitor] — 04/18/13 @ 03:23

  • Hexlator
    thank you sir ! u saved my day !
    greetings :)

    Comment by Hexlator [Visitor] — 08/27/13 @ 22:19

Leave a comment

Allowed XHTML tags: <p, ul, ol, li, dl, dt, dd, address, blockquote, ins, del, span, bdo, br, em, strong, dfn, code, samp, kdb, var, cite, abbr, acronym, q, sub, sup, tt, i, b, big, small>

(Line breaks become <br />)
(Set cookies for name, email & url)

powered by  b2evolution