title: Error Could not find or load main class
body: <p>I have a embedded jetty java application, which starts itself up and serving requests at the mentioned routes. While testing it is working good. Now that I want to deploy this java application via war file it is giving me issues.</p>
  
  <ol>
  <li><p>While running <code>java -jar server--1.0-SNAPSHOT.war</code> : It is giving me error as <code>Error: Could not find or load main class com.server.core.App</code></p></li>
  <li><p>This one will come after the 1st issue is fixed, how to include all the dependencies into the war file.</p></li>
  </ol>
  
  <p>Here is my 
  <code>pom.xml</code>
  <a href="https://gist.github.com/shadow-fox/24ec2c7d40f4b0e6aae5" rel="nofollow">https://gist.github.com/shadow-fox/24ec2c7d40f4b0e6aae5</a></p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;project xmlns="http://maven.apache.org/POM/4.0.0"
           xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
           xsi:schemaLocation="http://maven.apache.org/POM/4.0.0                    http://maven.apache.org/xsd/maven-4.0.0.xsd"&gt;
      &lt;modelVersion&gt;4.0.0&lt;/modelVersion&gt;
  
      &lt;groupId&gt;com.server&lt;/groupId&gt;
      &lt;artifactId&gt;server&lt;/artifactId&gt;
      &lt;version&gt;1.0-SNAPSHOT&lt;/version&gt;
      &lt;packaging&gt;war&lt;/packaging&gt;
  
      &lt;dependencies&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;org.eclipse.jetty&lt;/groupId&gt;
              &lt;artifactId&gt;jetty-server&lt;/artifactId&gt;
              &lt;version&gt;${jetty-version}&lt;/version&gt;
          &lt;/dependency&gt;
  
          &lt;dependency&gt;
              &lt;groupId&gt;org.eclipse.jetty&lt;/groupId&gt;
              &lt;artifactId&gt;jetty-servlet&lt;/artifactId&gt;
              &lt;version&gt;${jetty-version}&lt;/version&gt;
          &lt;/dependency&gt;
  
          &lt;dependency&gt;
              &lt;groupId&gt;org.eclipse.jetty&lt;/groupId&gt;
              &lt;artifactId&gt;jetty-util&lt;/artifactId&gt;
              &lt;version&gt;${jetty-version}&lt;/version&gt;
          &lt;/dependency&gt;
  
          &lt;dependency&gt;
              &lt;groupId&gt;org.glassfish.jersey.containers&lt;/groupId&gt;
              &lt;artifactId&gt;jersey-container-servlet-core&lt;/artifactId&gt;
              &lt;version&gt;${jersey-version}&lt;/version&gt;
          &lt;/dependency&gt;
  
          &lt;dependency&gt;
              &lt;groupId&gt;org.glassfish.jersey.core&lt;/groupId&gt;
              &lt;artifactId&gt;jersey-server&lt;/artifactId&gt;
              &lt;version&gt;${jersey-version}&lt;/version&gt;
          &lt;/dependency&gt;
  
          &lt;dependency&gt;
              &lt;groupId&gt;org.glassfish.jersey.containers&lt;/groupId&gt;
              &lt;artifactId&gt;jersey-container-jetty-http&lt;/artifactId&gt;
              &lt;version&gt;${jersey-version}&lt;/version&gt;
          &lt;/dependency&gt;
  
          &lt;dependency&gt;
              &lt;groupId&gt;org.glassfish.jersey.media&lt;/groupId&gt;
              &lt;artifactId&gt;jersey-media-moxy&lt;/artifactId&gt;
              &lt;version&gt;${jersey-version}&lt;/version&gt;
          &lt;/dependency&gt;
  
          &lt;dependency&gt;
              &lt;groupId&gt;org.glassfish.jersey.core&lt;/groupId&gt;
              &lt;artifactId&gt;jersey-client&lt;/artifactId&gt;
              &lt;version&gt;${jersey-version}&lt;/version&gt;
          &lt;/dependency&gt;
  
          &lt;dependency&gt;
              &lt;groupId&gt;com.fasterxml.jackson.core&lt;/groupId&gt;
              &lt;artifactId&gt;jackson-core&lt;/artifactId&gt;
              &lt;version&gt;${jackson-version}&lt;/version&gt;
          &lt;/dependency&gt;
  
          &lt;dependency&gt;
              &lt;groupId&gt;com.fasterxml.jackson.core&lt;/groupId&gt;
              &lt;artifactId&gt;jackson-databind&lt;/artifactId&gt;
              &lt;version&gt;${jackson-version}&lt;/version&gt;
          &lt;/dependency&gt;
  
          &lt;dependency&gt;
              &lt;groupId&gt;com.fasterxml.jackson.core&lt;/groupId&gt;
              &lt;artifactId&gt;jackson-annotations&lt;/artifactId&gt;
              &lt;version&gt;${jackson-version}&lt;/version&gt;
          &lt;/dependency&gt;
  
          &lt;dependency&gt;
              &lt;groupId&gt;org.apache.logging.log4j&lt;/groupId&gt;
              &lt;artifactId&gt;log4j-core&lt;/artifactId&gt;
              &lt;version&gt;${log4j-version}&lt;/version&gt;
          &lt;/dependency&gt;
  
          &lt;dependency&gt;
              &lt;groupId&gt;junit&lt;/groupId&gt;
              &lt;artifactId&gt;junit&lt;/artifactId&gt;
              &lt;version&gt;${junit-version}&lt;/version&gt;
              &lt;scope&gt;test&lt;/scope&gt;
          &lt;/dependency&gt;
      &lt;/dependencies&gt;
  
      &lt;properties&gt;
          &lt;project.build.sourceEncoding&gt;UTF-8&lt;/project.build.sourceEncoding&gt;
          &lt;jdk-version&gt;1.8&lt;/jdk-version&gt;
          &lt;jetty-version&gt;9.3.3.v20150827&lt;/jetty-version&gt;
          &lt;jersey-version&gt;2.21&lt;/jersey-version&gt;
          &lt;junit-version&gt;4.12&lt;/junit-version&gt;
          &lt;jackson-version&gt;2.6.1&lt;/jackson-version&gt;
          &lt;log4j-version&gt;2.3&lt;/log4j-version&gt;
          &lt;mvn-compiler&gt;3.3&lt;/mvn-compiler&gt;
          &lt;mvn-war&gt;2.6&lt;/mvn-war&gt;
      &lt;/properties&gt;
  
      &lt;build&gt;
          &lt;plugins&gt;
              &lt;plugin&gt;
                  &lt;groupId&gt;org.apache.maven.plugins&lt;/groupId&gt;
                  &lt;artifactId&gt;maven-compiler-plugin&lt;/artifactId&gt;
                  &lt;version&gt;${mvn-compiler}&lt;/version&gt;
                  &lt;configuration&gt;
                      &lt;source&gt;${jdk-version}&lt;/source&gt;
                      &lt;target&gt;${jdk-version}&lt;/target&gt;
                  &lt;/configuration&gt;
              &lt;/plugin&gt;
              &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;${mvn-war}&lt;/version&gt;
                  &lt;configuration&gt;
                      &lt;failOnMissingWebXml&gt;false&lt;/failOnMissingWebXml&gt;
                      &lt;archive&gt;
                          &lt;manifest&gt;
                              &lt;addClasspath&gt;true&lt;/addClasspath&gt;
                              &lt;classpathPrefix&gt;lib/&lt;/classpathPrefix&gt;
                              &lt;mainClass&gt;com.server.core.App&lt;/mainClass&gt;
                          &lt;/manifest&gt;
                      &lt;/archive&gt;
                  &lt;/configuration&gt;
              &lt;/plugin&gt;
          &lt;/plugins&gt;
      &lt;/build&gt;
  &lt;/project&gt;
  </code></pre>
  
  <p>Where I might have messed up: The classpathPrefix not sure what to set here. My classes goes to target dir as default (Using IDEA Intellij) . The mainClass does exist on the same path.</p>
  
  <p><code>App.java</code></p>
  
  <pre><code>package com.server.core;
  
  import com.server.core.filters.RequestFilter;
  
  import org.apache.logging.log4j.LogManager;
  import org.apache.logging.log4j.Logger;
  import org.eclipse.jetty.server.Server;
  import org.eclipse.jetty.server.ServerConnector;
  import org.eclipse.jetty.servlet.ServletContextHandler;
  import org.eclipse.jetty.servlet.ServletHolder;
  import org.glassfish.jersey.servlet.ServletContainer;
  
  import java.util.EnumSet;
  
  import javax.servlet.DispatcherType;
  
  public class App {
  
      private static final Logger logger = LogManager.getLogger(App.class);
  
      public static void main(String[] args) throws Exception {
  
          Server server = new Server();
          ServerConnector connector = new ServerConnector(server);
          connector.setPort(8080);
          server.addConnector(connector);
  
          ServletContextHandler context = new ServletContextHandler(ServletContextHandler.SESSIONS);
          context.setContextPath("/");
          context.addFilter(RequestFilter.class, "/*", EnumSet.of(DispatcherType.INCLUDE,
                  DispatcherType.REQUEST, DispatcherType.ASYNC, DispatcherType.ERROR,
                  DispatcherType.FORWARD));
          server.setHandler(context);
  
          ServletHolder servletHolder = new ServletHolder(ServletContainer.class);
          servletHolder.setInitOrder(0);
          servletHolder.setInitParameter("jersey.config.server.provider.packages", "com/server/core/endpoints");
          context.addServlet(servletHolder, "/*");
  
          try {
              server.start();
              logger.debug("Server started");
              logger.debug(server);
              server.join();
          } catch (Throwable t) {
              logger.error(System.err);
          } finally {
              server.destroy();
          }
      }
  }
  </code></pre>
  
  <p>There are lot of questions similar to this but couldn't find for this use-case.</p>