title: Embedded Jetty : how to use a .war that is included in the .jar from which Jetty starts?
body: <p>I'm trying to generate a .jar containing a <em>main()</em> that would start Jetty.</p>
  
  <p>My problem is that I'd like the .war that Jetty loads <strong><em>to be included in the same .jar</em></strong>.</p>
  
  <p>I've been able to create the .jar containing the .war with :</p>
  
  <p><strong>In the POM.xml :</strong></p>
  
  <pre><code>&lt;plugin&gt;
      &lt;artifactId&gt;maven-assembly-plugin&lt;/artifactId&gt;
      &lt;version&gt;2.3&lt;/version&gt;
      &lt;configuration&gt;
          &lt;finalName&gt;myApp&lt;/finalName&gt;
          &lt;appendAssemblyId&gt;false&lt;/appendAssemblyId&gt;
          &lt;archive&gt;
              &lt;manifest&gt;
                  &lt;mainClass&gt;com.myApp.Server&lt;/mainClass&gt;
              &lt;/manifest&gt;
          &lt;/archive&gt;
          &lt;descriptors&gt;
              &lt;descriptor&gt;src/main/resources/executable-jar-assembly.xml&lt;/descriptor&gt;
          &lt;/descriptors&gt;
      &lt;/configuration&gt;
      &lt;executions&gt;
          &lt;execution&gt;
              &lt;id&gt;make-my-jar-with-dependencies&lt;/id&gt;
              &lt;phase&gt;package&lt;/phase&gt;
              &lt;goals&gt;
                  &lt;goal&gt;single&lt;/goal&gt;
              &lt;/goals&gt;
          &lt;/execution&gt;
      &lt;/executions&gt;
  &lt;/plugin&gt;
  </code></pre>
  
  <p><strong>executable-jar-assembly.xml :</strong> </p>
  
  <pre><code>&lt;assembly xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.0" 
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.0 http://maven.apache.org/xsd/assembly-1.1.0.xsd"&gt;
  
  &lt;id&gt;jar-with-dependencies-and-war&lt;/id&gt;
  &lt;formats&gt;
  &lt;format&gt;jar&lt;/format&gt;
  &lt;/formats&gt;
  &lt;includeBaseDirectory&gt;false&lt;/includeBaseDirectory&gt;
  &lt;dependencySets&gt;
      &lt;dependencySet&gt;
          &lt;outputDirectory&gt;/&lt;/outputDirectory&gt;
          &lt;useProjectArtifact&gt;false&lt;/useProjectArtifact&gt;
          &lt;unpack&gt;true&lt;/unpack&gt;
          &lt;scope&gt;runtime&lt;/scope&gt;
      &lt;/dependencySet&gt;
  &lt;/dependencySets&gt;
  &lt;fileSets&gt;
      &lt;fileSet&gt;
          &lt;directory&gt;target/classes/&lt;/directory&gt;
          &lt;outputDirectory&gt;/&lt;/outputDirectory&gt;
      &lt;/fileSet&gt;
      &lt;fileSet&gt;
          &lt;directory&gt;target/&lt;/directory&gt;
          &lt;includes&gt;
              &lt;include&gt;
                  myApp.war
              &lt;/include&gt;
          &lt;/includes&gt;
          &lt;outputDirectory&gt;/&lt;/outputDirectory&gt;
      &lt;/fileSet&gt;
  &lt;/fileSets&gt;
  </code></pre>
  
  <p></p>
  
  <p><strong>The code to set the war in Jetty :</strong></p>
  
  <pre><code>handler.setWar("myApp.war");
  </code></pre>
  
  <p><strong>... I also tried :</strong></p>
  
  <pre><code>URL res = Server.class.getResource("myApp.war");
  handler.setWar(res.toExternalForm());
  </code></pre>
  
  <p><strong>... and :</strong></p>
  
  <pre><code>URL res = Thread.currentThread().getContextClassLoader().getSystemResource("myApp.war");
  handler.setWar(res.toExternalForm());
  </code></pre>
  
  <p>But nothing works!</p>
  
  <p>Using that last example code to start Jetty, the server <em>seems</em> to start correctly but no requests work. The configuration is obviously wrong.</p>
  
  <p>I know there are some workarounds to make a .war itself executable, but I'd like to make the "<em>.war inside the .jar</em>" work.</p>
  
  <p>Any idea how the .war should be configured?</p>