title: Spring application with embedded jetty can't find webdefault.xml if running from jar
body: <p>I have spring application which uses embedded Jetty instance.</p>
  
  <pre><code>project
     | src
        | controller
        | webapps
            | jsp
            | WEB-INF
                | web.xml
                | applicationContext.xml
                | spring-servlet.xml
  </code></pre>
  
  <p>my jar has the same tree structure but I keep getting</p>
  
  <pre><code>    d:\test&gt;java -jar springtest.jar
  2011-11-22 15:37:02.576:INFO::jetty-7.x.y-SNAPSHOT
  2011-11-22 15:37:02.686:WARN::Failed startup of context o.e.j.w.WebAppContext{/,[file:/C:/Users/me/AppData/Local/Temp/jetty-0.0.0.0-8080-webapps-_-any-/webinf
  /, jar:file:/d:/test/springtest.jar!/org/jcvi/webapps/]}
  java.io.FileNotFoundException: d:\test\org\eclipse\jetty\webapp\webdefault.xml (The system cannot find
  the path specified)
          at java.io.FileInputStream.open(Native Method)
          at java.io.FileInputStream.&lt;init&gt;(FileInputStream.java:106)
          at java.io.FileInputStream.&lt;init&gt;(FileInputStream.java:66)
          at sun.net.www.protocol.file.FileURLConnection.connect(FileURLConnection.java:70)
          at sun.net.www.protocol.file.FileURLConnection.getInputStream(FileURLConnection.java:161)
          at com.sun.org.apache.xerces.internal.impl.XMLEntityManager.setupCurrentEntity(XMLEntityManager.java:653)
          at com.sun.org.apache.xerces.internal.impl.XMLVersionDetector.determineDocVersion(XMLVersionDetector.java:186)
          at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:772)
          at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:737)
          at com.sun.org.apache.xerces.internal.parsers.XMLParser.parse(XMLParser.java:119)
          at com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.parse(AbstractSAXParser.java:1205)
          at com.sun.org.apache.xerces.internal.jaxp.SAXParserImpl$JAXPSAXParser.parse(SAXParserImpl.java:522)
          at javax.xml.parsers.SAXParser.parse(SAXParser.java:395)
          at org.eclipse.jetty.xml.XmlParser.parse(XmlParser.java:188)
          at org.eclipse.jetty.xml.XmlParser.parse(XmlParser.java:204)
          at org.eclipse.jetty.webapp.Descriptor.parse(Descriptor.java:60)
          at org.eclipse.jetty.webapp.WebDescriptor.parse(WebDescriptor.java:140)
          at org.eclipse.jetty.webapp.MetaData.setDefaults(MetaData.java:141)
          at org.eclipse.jetty.webapp.WebXmlConfiguration.preConfigure(WebXmlConfiguration.java:46)
          at org.eclipse.jetty.webapp.WebAppContext.preConfigure(WebAppContext.java:412)
          at org.eclipse.jetty.webapp.WebAppContext.doStart(WebAppContext.java:448)
          at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:58)
          at org.eclipse.jetty.server.handler.HandlerWrapper.doStart(HandlerWrapper.java:89)
          at org.eclipse.jetty.server.Server.doStart(Server.java:258)
          at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:58)
          at org.jcvi.ServerRunner.startServer(ServerRunner.java:83)
          at org.jcvi.MainServer.main(MainServer.java:18)
  2011-11-22 15:37:02.748:INFO::Started SelectChannelConnector@0.0.0.0:8080 STARTING
  </code></pre>
  
  <p>I have following java class which runs jetty server instance</p>
  
  <pre><code>String webDir = this.getClass().getClassLoader().getResource("webapps").toExternalForm();
  Server server = new Server(8080);
  
  WebAppContext context = new WebAppContext();
  context.setContextPath("/");
  context.setResourceBase(webDir);
  context.setParentLoaderPriority(true);
  HandlerList handlers = new HandlerList();
  handlers.setHandlers(new Handler[] { context, new DefaultHandler() });
  server.setHandler(context);
  server.start();
  </code></pre>
  
  <p>my web.xml looks like</p>
  
  <pre><code>&lt;welcome-file-list&gt;
          &lt;welcome-file&gt;index.jsp&lt;/welcome-file&gt;
      &lt;/welcome-file-list&gt;
  
      &lt;context-param&gt;
          &lt;param-name&gt;contextConfigLocation&lt;/param-name&gt;
          &lt;param-value&gt;/WEB-INF/applicationContext.xml&lt;/param-value&gt;
      &lt;/context-param&gt;
  
      &lt;listener&gt;
          &lt;listener-class&gt;
              org.springframework.web.context.ContextLoaderListener
          &lt;/listener-class&gt;
      &lt;/listener&gt;
  
      &lt;servlet&gt;
          &lt;servlet-name&gt;spring&lt;/servlet-name&gt;
              &lt;servlet-class&gt;
                  org.springframework.web.servlet.DispatcherServlet
              &lt;/servlet-class&gt;
          &lt;load-on-startup&gt;2&lt;/load-on-startup&gt;
      &lt;/servlet&gt;
  
      &lt;servlet-mapping&gt;
          &lt;servlet-name&gt;spring&lt;/servlet-name&gt;
          &lt;url-pattern&gt;/&lt;/url-pattern&gt;
      &lt;/servlet-mapping&gt;
  </code></pre>
  
  <p>this application runs fine if I run inside IDE, but it fails with JAR.
  How can I resolve this issue so that I can have single jar file which has the web application in it?</p>