Deploying war file using xml on jetty9 Code Answer

Hello Developer, Hope you guys are doing great. Today at Tutorial Guruji Official website, we are sharing the answer of Deploying war file using xml on jetty9 without wasting too much if your time.

The question is published on by Tutorial Guruji team.

I am trying to deploy a war file on jetty9, it works fine if I drop it into webapps folder but I want to deploy it using a xml file.

Here’s the exception I am getting:

2015-10-22 17:36:39.593:WARN:oejw.WebAppContext:main: Failed startup of context o.e.j.w.WebAppContext@61a485d2{/myapp,file:///tmp/jetty-openbd.war-_myapp-any-1881803922382581907.dir/webapp/,null}{/opt/}
    at org.eclipse.jetty.webapp.MetaInfConfiguration.preConfigure(
    at org.eclipse.jetty.webapp.WebAppContext.preConfigure(
    at org.eclipse.jetty.webapp.WebAppContext.doStart(
    at org.eclipse.jetty.util.component.AbstractLifeCycle.start(
    at org.eclipse.jetty.xml.XmlConfiguration$
    at Method)
    at org.eclipse.jetty.xml.XmlConfiguration.main(
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(
    at java.lang.reflect.Method.invoke(
    at org.eclipse.jetty.start.Main.invokeMain(
    at org.eclipse.jetty.start.Main.start(
    at org.eclipse.jetty.start.Main.main(

and my xml :

<?xml version="1.0"  encoding="ISO-8859-1"?>
<!DOCTYPE Configure PUBLIC "-//Jetty//Configure//EN"

<Configure class="org.eclipse.jetty.webapp.WebAppContext">
  <Set name="contextPath">/myapp</Set>
  <Set name="war">/opt/</Set>

I tried with <Set name="extractWAR">true</Set> with no luck.

I also used --debug which didn’t provide any clue..

What am I doing wrong? Jetty version: jetty-9.3.3.v20150827


So for your scenario you’ll need to understand how ${jetty.base} and ${jetty.home} operate.

Step 1: The ${jetty.home} directory

Download and unpack the jetty distribution, anywhere, to any path you want to.

This is now your ${jetty.home} directory.

These are the most important facts about ${jetty.home}

  • Don’t edit it.
  • Don’t change a thing.
  • Don’t delete anything.
  • Leave it alone.

You can have multiple ${jetty.home} directories on your machine if you want. They don’t step on each other or cause any problems.

Step 2: The ${jetty.base} directory

Create a new directory OUTSIDE of the ${jetty.home} directory.

This new, now blank, directory is the start of your ${jetty.base}.

A ${jetty.base} represent the configuration for a specific instance of Jetty. You can have multiple ${jetty.base} directories as well. Each directory represent a unique instance of a running Jetty.

The fundamental configuration for a ${jetty.base} is the start.ini which is a set of command line arguments used to start jetty. (Similar to how all of the Eclipse RT projects out there work)

To initialize your ${jetty.base} using command line tooling you can utilize the ${jetty.home}/start.jar and its --add-to-start=<module> facilities.


$ cd /path/to/my.base
$ java -jar /path/to/jetty-dist/start.jar --add-to-start=http,deploy,websocket

Congrats you just initialized your ${jetty.base} directory.

Step 3: Adding your WebApps

Since you chose the deploy module in the above step, you now have a ${jetty.base}/webapps which is used by Jetty to auto-deploy the various web applications found within.

See the documentation on the Deployment Architecture to understand what it looks for and how it deploys.

In your case, just put your myapp.xml into the ${jetty.base}/webapps/ directory.

Note: Using the deploy module as-is, will only monitor and deploy from the ${jetty.base}/webapps/ directory. No other directory is looked in, or monitored for web applications. Not even the ${jetty.home}/webapps/ directory.

The monitored directory can be configured via a property in your ${jetty.base}/start.ini. Simply set jetty.deploy.monitoredDir=<relative-path> and this new path will be monitored (no editing of jetty-deploy.xml required). The monitored directory is configured to always be under the specified ${jetty.base} directory. Seeing as the ${jetty.base} directory can be anywhere on your filesystem, there should be no issues with using the ${jetty.base} facilities.

Step 4: Run Jetty

This isn’t that hard either.

$ cd /path/to/my.base
$ java -jar /path/to/jetty-dist/start.jar

Congrats you have a running jetty.

Step 5: (Bonus) Listing the Configuration

There’s 2 ways to see what the configuration looks like.

  1. See the server configuration, before you start jetty.
$ cd /path/to/my.base
$ java -jar /path/to/jetty-dist/start.jar --list-config
  1. See the server state after it is fully started.
$ cd /path/to/my.base
$ java -jar /path/to/jetty-dist/start.jar jetty.server.dumpAfterStart=true
We are here to answer your question about Deploying war file using xml on jetty9 - If you find the proper solution, please don't forgot to share this with your team members.

Related Posts

Tutorial Guruji