title: How do I run a class in a WAR from the command line?
body: <p>I have a Java class which has a main and I used to run as a standalone app from the command line e.g.</p>
  
  <pre><code>java -jar myjar.jar params
  </code></pre>
  
  <p>I needed to repackage the code to run under apache and all my code, including the entry point class from the old jar, has ended up in a WAR file for easy deplyment into the web server.</p>
  
  <p>However, I still want to be able to run it from the command line and the code has not changed and is all in there, I just can't figure out how to get it to run.</p>
  
  <p>Here's what I tried...</p>
  
  <p>I presumed the WAR was just like a jar, so</p>
  
  <pre><code>java -jar mywar.war params
  </code></pre>
  
  <p>That failed saying there was no main class defined in the manifest.</p>
  
  <p>I manually added a manifest to the war and tried again, with the same effect.</p>
  
  <p>I noticed that in my war I had a folder called META-INF containing a manifest.mf, so I added a line to that declaring my main class as I would to a normal manifest...</p>
  
  <pre><code>Manifest-Version: 1.0
  Main-Class: mypackage.MyEntryPointClass
  </code></pre>
  
  <p>This gave a <code>noClassDefFoundError mypackage.MyEntryPointClass</code>, which is progress of a sort.  That led me to believe that it was just a path issue, so I tried</p>
  
  <pre><code>Manifest-Version: 1.0
  Main-Class: WEB-INF.classes.mypackage.MyEntryPointClass
  </code></pre>
  
  <p>I now get the same error, but with a stack trace...</p>
  
  <pre><code>Exception in thread "main" java.lang.NoClassDefFoundError: WEB-INF/classes/mypackage/MyEntryPointClass (wrong name: mypackage/MyEntryPointClass)
          at java.lang.ClassLoader.defineClass1(Native Method)
          at java.lang.ClassLoader.defineClass(Unknown Source)
          at java.security.SecureClassLoader.defineClass(Unknown Source)
          at java.net.URLClassLoader.defineClass(Unknown Source)
          at java.net.URLClassLoader.access$100(Unknown Source)
          at java.net.URLClassLoader$1.run(Unknown Source)
          at java.security.AccessController.doPrivileged(Native Method)
          at java.net.URLClassLoader.findClass(Unknown Source)
          at java.lang.ClassLoader.loadClass(Unknown Source)
          at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
          at java.lang.ClassLoader.loadClass(Unknown Source)
          at java.lang.ClassLoader.loadClassInternal(Unknown Source)
  </code></pre>
  
  <p>I've googled for a bit but can't find anything which answers my question, and I read a couple of other questions here which are slightly different, so I thought I would post.</p>
  
  <p>Java 1.5, not that I think that should make any difference.</p>