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.
- 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
- 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\.
- I created the following script called "create_jetty_service.bat":
prunsrv //IS//JettyService --DisplayName="Jetty v8.1.3 Service" --Startup=auto(Note - when creating this .bat file, the above should all be on one line!)
--StartMode=java --StopMode=java --Classpath=C:\jetty\jetty-distribution-8.1.3.v20120416\start.jar
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.
- Once you've run the above create script, you can test the start-up of the service using this command:
- You can also delete the service using this command (necessary if you want to re-create it with different options).
I hope this helps someone out there.
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>