Windows Service for Jetty 7

Last modified by Quentin Conner on 08/02/2013

Nov 07 2011

How to install Jetty 7 as a Windows service

Earlier versions of Jetty came with a Windows Service wrapper but Jetty 7 does not.  To use Jetty in a production environment it is helpful to create a Windows service to run Jetty so that the service may run without manual intervention, like when the machine boots.  

One way to accomplish this task is to make use of the (Jakarta) Commons Daemon project.  In the example that follows I am using XWiki 3.2 that bundles Jetty 7.  XWiki 3.2 is unzipped to C:\apps\xwiki32 and Jetty 7 resides within at C:\apps\xwiki32\jetty.

Commons Daemon

First read about the commons daemon project at the following URL:

Download the native binaries for Windows from this URL:

The daemon project essentially provides two Executables for the Windows operating system:  prunmgr.exe and prunsrv.exe, collectively referred to as procrun.  In essence, procrun provides the capability to run arbitrary Java main methods as a Windows service.

Determine Java arguments when starting Jetty

In my case I wanted to run a web application called XWiki deployed to Jetty, and have Jetty run under the Windows SYSTEM account whenever the machine boots up.  I modified the start_xwiki.bat batch file to echo the Java command line before running java so I could capture all the arguments to Java.  You'll need these later when configuring procrun.

In my case, the Java command line XWiki 3.2 wanted to use when running Java was:

java -Xmx512m -XX:MaxPermSize=128m -Djetty.port=8080 -Djetty.home=jetty -DSTOP.KEY=xwiki -DSTOP.PORT=8079 -Dfile.encoding=UTF8 -Dorg.mortbay.jetty.Request.maxFormContentSize=1000000 -jar jetty/start.jar

Rename prunsrv.exe and prunmgr.exe to reflect your Jetty Service

Because Windows' Service manager (accessible from the Control Panel) identifies services by the executable filename used to start and stop the service, it is helpful to rename the two windows executables, prunsrv.exe and prunmgr.exe to reflect the fact this is a XWiki Jetty service.

cd \apps\xwiki32
copy prunsrv.exe XWikiJettyService.exe
copy prunmgr.exe XWikiJettyServiceManager.exe

Install Service

The following step configures procrun and installs the Windows Service.  The JVM arguments below correspond to the arguments we captured from the original Java command line invocation from start_xwiki.bat.

XWikiJettyService.exe  //IS//XWikiJettyServiceManager --DisplayName="XWiki Jetty Service" --Install=C:\apps\xwiki32\XWikiJettyService.exe --LogPath=C:\apps\xwiki32\jetty\logs --LogLevel=Debug --StdOutput=auto --StdError=auto --StartMode=Java --StopMode=Java --Jvm=auto --Startup=auto --JvmMx=512 --StartPath=C:\apps\xwiki32 ++JvmOptions=-XX:MaxPermSize=128m --Classpath=C:\apps\xwiki32\jetty\start.jar --StartClass=org.eclipse.jetty.start.Main --StopClass=org.eclipse.jetty.start.Main ++StopParams=--stop ++JvmOptions=-Djetty.home=C:\apps\xwiki32\jetty ++JvmOptions=-Djetty.port=8080 ++JvmOptions=-DSTOP.PORT=8079 ++JvmOptions=-DSTOP.KEY=xwiki ++JvmOptions=-Djetty.logs=C:\apps\xwiki32\jetty\logs ++JvmOptions=-Dfile.encoding=UTF8 ++JvmOptions=-Dorg.mortbay.jetty.Request.maxFormContentSize=1000000

Test procrun

The following will allow you to test your shiny new Windows Service by running it in the foreground so you can see any errors that may occur if the configuration isn't quite right.

XWikiJettyService.exe //TS/XWikiJettyServiceManager

Procrun logs, Stdout and Stderr logs for your service

These logs will be saved to the Jetty logs directory in the scenario described.  The location of the procrun daemon logs are specified by the
--LogPath=C:\apps\xwiki32\jetty\logs argument when you ran the XWikiJettyService.exe (prunsrv.exe) above.

The actual daemon stdout and stderr logs for Jetty are controlled by the -Djetty.logs=C:\apps\xwiki32\jetty\logs JVM argument.

Remove Service

cd \apps\xwiki32
XWikiJettyService.exe  //DS//XWikiJettyServiceManager

Created by Quentin Conner on 08/02/2013
This website content is not licensed to you. All rights reserved.
XWiki Enterprise 9.11.1 - Documentation