title: Self-contained war file with Tomcat embedded?
body: <p>Is there anyone who has succeeded in making a self-contained .war file using Tomcat 7 embedded ? With Maven that is.</p>
  
  <p>I mean with "self-contained" that the war file can also be used at the command line as:</p>
  
  <p>java -jar application.war</p>
  
  <p>With which it should pick up the Main Class of META-INF/MANIFEST.MF and run the application with the provided embedded Tomcat 7.</p>
  
  <p>I managed to make it run as such, but I can't seem to be able to package it into a .war file that does the same.</p>
  
  <p>Anybody has a link to documentation of some sorts ?</p>
  
  <p>TIA !!!</p>
  
  <p>Jan</p>
  
  <p>Adding an extract from the pom.xml :</p>
  
  <pre><code>  &lt;plugin&gt;
      &lt;groupId&gt;org.apache.maven.plugins&lt;/groupId&gt;
      &lt;artifactId&gt;maven-war-plugin&lt;/artifactId&gt;
      &lt;version&gt;2.1.1&lt;/version&gt;
      &lt;configuration&gt;
        &lt;failOnMissingWebXml&gt;false&lt;/failOnMissingWebXml&gt;
        &lt;archive&gt;
          &lt;manifest&gt;
            &lt;mainClass&gt;EmbeddedMain&lt;/mainClass&gt;
            &lt;addClasspath&gt;true&lt;/addClasspath&gt;
            &lt;classpathPrefix&gt;WEB-INF/lib/&lt;/classpathPrefix&gt;
          &lt;/manifest&gt;
        &lt;/archive&gt;
        &lt;webResources&gt;
          &lt;resource&gt;
            &lt;directory&gt;target/classes&lt;/directory&gt;
          &lt;/resource&gt;
        &lt;/webResources&gt;
      &lt;/configuration&gt;
    &lt;/plugin&gt;
  </code></pre>
  
  <p>Where "EmbeddedMain" is the class containing the main() method. And although everything seems to be in its place, I'm still getting:</p>
  
  <pre><code>Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/catalina/LifecycleListener
  Caused by: java.lang.ClassNotFoundException: org.apache.catalina.LifecycleListener
      at java.net.URLClassLoader$1.run(URLClassLoader.java:202)
      at java.security.AccessController.doPrivileged(Native Method)
      at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
      at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
      at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
      at java.lang.ClassLoader.loadClass(ClassLoader.java:247)
  Could not find the main class: EmbeddedMain. Program will exit.
  </code></pre>
  
  <p>MANIFEST.MF seems to be okay: WEB-INF/lib/tomcat-embed-core-7.0.22.jar contains the missing class.</p>
  
  <pre><code>Manifest-Version: 1.0
  Archiver-Version: Plexus Archiver
  Created-By: Apache Maven
  Built-By: jan
  Build-Jdk: 1.6.0_29
  Main-Class: EmbeddedMain
  Class-Path: WEB-INF/lib/spring-web-3.0.6.RELEASE.jar WEB-INF/lib/aopal
   liance-1.0.jar WEB-INF/lib/spring-beans-3.0.6.RELEASE.jar WEB-INF/lib
   /spring-core-3.0.6.RELEASE.jar WEB-INF/lib/jwt-3.1.11.jar WEB-INF/lib
   /commons-fileupload-1.2.1.jar WEB-INF/lib/commons-io-1.4.jar WEB-INF/
   lib/next-persistence-0.0.3.jar WEB-INF/lib/hibernate-entitymanager-3.
   6.7.Final.jar WEB-INF/lib/hibernate-core-3.6.7.Final.jar WEB-INF/lib/
   antlr-2.7.6.jar WEB-INF/lib/dom4j-1.6.1.jar WEB-INF/lib/hibernate-com
   mons-annotations-3.2.0.Final.jar WEB-INF/lib/jta-1.1.jar WEB-INF/lib/
   cglib-2.2.jar WEB-INF/lib/javassist-3.12.0.GA.jar WEB-INF/lib/hiberna
   te-jpa-2.0-api-1.0.1.Final.jar WEB-INF/lib/kryo-1.04.jar WEB-INF/lib/
   asm-3.2.jar WEB-INF/lib/reflectasm-1.01.jar WEB-INF/lib/minlog-1.2.ja
   r WEB-INF/lib/annotations-1.3.9.jar WEB-INF/lib/tomcat-embed-core-7.0
   .22.jar WEB-INF/lib/tomcat-embed-jasper-7.0.22.jar WEB-INF/lib/tomcat
   -embed-logging-juli-7.0.22.jar WEB-INF/lib/derby-10.8.1.2.jar WEB-INF
   /lib/spring-context-3.0.6.RELEASE.jar WEB-INF/lib/spring-aop-3.0.6.RE
   LEASE.jar WEB-INF/lib/spring-expression-3.0.6.RELEASE.jar WEB-INF/lib
   /spring-asm-3.0.6.RELEASE.jar WEB-INF/lib/spring-orm-3.0.6.RELEASE.ja
   r WEB-INF/lib/spring-jdbc-3.0.6.RELEASE.jar WEB-INF/lib/spring-tx-3.0
   .6.RELEASE.jar WEB-INF/lib/commons-lang-2.5.jar WEB-INF/lib/slf4j-api
   -1.6.3.jar WEB-INF/lib/slf4j-log4j12-1.6.3.jar WEB-INF/lib/log4j-1.2.
   14.jar WEB-INF/lib/jcl-over-slf4j-1.6.3.jar WEB-INF/lib/commons-loggi
   ng-1.1.jar WEB-INF/lib/commons-collections-3.2.jar
  </code></pre>