java.lang.ClassNotFoundException:org.eclipse.jetty.Server

时间:2016-05-11 16:50:55

标签: java jetty maven-3

我正在尝试运行maven项目,当我运行mvn install时一切正常我获得了构建成功qnd当我尝试午餐时我得到了以下异常:

Exception in thread "main" java.lang.ClassNotFoundException: org.eclipse.jetty.Server
at java.net.URLClassLoader$1.run(URLClassLoader.java:366)
at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
at java.lang.ClassLoader.loadClass(ClassLoader.java:425)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
at java.lang.ClassLoader.loadClass(ClassLoader.java:358)
at org.eclipse.jetty.util.Loader.loadClass(Loader.java:86)
at org.eclipse.jetty.xml.XmlConfiguration$JettyXmlConfiguration.nodeClass(XmlConfiguration.java:364)
at org.eclipse.jetty.xml.XmlConfiguration$JettyXmlConfiguration.configure(XmlConfiguration.java:292)
at org.eclipse.jetty.xml.XmlConfiguration.configure(XmlConfiguration.java:248)
at net.es.oscars.wbui.http.WebApp.main(WebApp.java:44)

当我运行mvn依赖:tree时,我得到了以下结果:

     maven-dependency-plugin:2.8:tree (default-cli) @ wbui ---
     [INFO] net.es.oscars:wbui:jar:0.0.1-SNAPSHOT
     [INFO] +- net.es.oscars:utils:jar:0.0.1-SNAPSHOT:compile
     [INFO] |  +- net.perfsonar:ps-api:jar:0.5:compile
     [INFO] |  |  +- commons-httpclient:commonhttpclient:jar:3.0.1:compile
     [INFO] |  |  |  +- junit:junit:jar:3.8.1:compile
     [INFO] |  |  |  \- commons-codec:commons-codec:jar:1.2:compile
     [INFO] |  |  +- org.jdom:jdom:jar:1.1:compile
     [INFO] |  |  +- org.jdom:jaxen-jdom:jar:1.0-FCS:compile
     [INFO] |  |  +- org.jdom:jaxen-core:jar:1.0-FCS:compile
     [INFO] |  |  \- org.jdom:saxpath:jar:1.0-FCS:compile
     [INFO] |  +- org.jyaml:jyaml:jar:1.3:compile
     [INFO] |  +- log4j:log4j:jar:1.2.17:compile
     [INFO] |  +- net.es.oscars:common-logging:jar:0.0.1-SNAPSHOT:compile
     [INFO] |  |  \- gov.lbl:netlogger:jar:4.1.2:compile
     [INFO] |  +- net.es.oscars:common-soap:jar:0.0.1-SNAPSHOT:compile
     [INFO] |  +- org.hibernate:hibernate-core:jar:3.3.1.GA:compile
     [INFO] |  |  +- antlr:antlr:jar:2.7.6:compile
      [INFO] |  |  +- commons-collections:commons-collections:jar:3.1:compile
     [INFO] |  |  \- dom4j:dom4j:jar:1.6.1:compile
     [INFO] |  |     \- xml-apis:xml-apis:jar:1.0.b2:compile
     [INFO] |  +- org.mortbay.jetty:jetty:jar:6.1.16:compile
     [INFO] |  |  +- org.mortbay.jetty:jetty-util:jar:6.1.16:compile
     [INFO] |  |  \- org.mortbay.jetty:servlet-api:jar:2.5-20081211:compile
     [INFO] |  +- org.opensymphony.quartz:quartz:jar:1.6.1:compile
     [INFO] |  +- org.apache.ws.security:wss4j:jar:1.5.8:compile
     [INFO] |  |  +- commons-logging:commons-logging:jar:1.1:compile
     [INFO] |  |  |  +- logkit:logkit:jar:1.0.1:compile
     [INFO] |  |  |  +- avalon-framework:avalon-framework:jar:4.1.3:compile
     [INFO] |  |  |  \- javax.servlet:servlet-api:jar:2.3:compile
     [INFO] |  |  +- org.apache.santuario:xmlsec:jar:1.4.3:compile
     [INFO] |  |  \- xalan:xalan:jar:2.7.1:compile
    [INFO] |  |     \- xalan:serializer:jar:2.7.1:compile
    [INFO] |  +- org.apache.cxf:cxf-rt-bindings-soap:jar:2.2.5:compile
    [INFO] |  |  +- org.apache.cxf:cxf-api:jar:2.2.5:compile
     [INFO] |  |  |  +- org.apache.geronimo.specs:geronimo-activation_1.1_spec:jar:1.0.2:compile
    [INFO] |  |  |  +- org.apache.ws.commons.schema:XmlSchema:jar:1.4.5:compile
    [INFO] |  |  |  +- org.apache.geronimo.specs:geronimo-annotation_1.0_spec:jar:1.1.1:compile
    [INFO] |  |  |  +- org.codehaus.woodstox:wstx-asl:jar:3.2.9:compile
    [INFO] |  |  |  +- org.apache.neethi:neethi:jar:2.0.4:compile
    [INFO] |  |  |  \- org.apache.cxf:cxf-common-schemas:jar:2.2.5:compile
    [INFO] |  |  +- org.apache.cxf:cxf-tools-common:jar:2.2.5:compile
    [INFO] |  |  |  +- wsdl4j:wsdl4j:jar:1.6.2:compile
    [INFO] |  |  |  \- com.sun.xml.bind:jaxb-impl:jar:2.1.12:compile
    [INFO] |  |  +- org.apache.cxf:cxf-rt-databinding-jaxb:jar:2.2.5:compile
   [INFO] |  |  |  \- org.apache.geronimo.specs:geronimo-javamail_1.4_spec:jar:1.6:compile
    [INFO] |  |  \- javax.xml.bind:jaxb-api:jar:2.1:compile
    [INFO] |  +- org.apache.cxf:cxf-rt-ws-security:jar:2.2.5:compile
    [INFO] |  |  +- org.apache.cxf:cxf-rt-core:jar:2.2.5:compile
    [INFO] |  |  |  \- org.springframework:spring-core:jar:2.5.5:compile
    [INFO] |  |  +- org.apache.cxf:cxf-common-utilities:jar:2.2.5:compile
    [INFO] |  |  |  +- org.springframework:spring-beans:jar:2.5.5:compile
    [INFO] |  |  |  +- org.springframework:spring-context:jar:2.5.5:compile
    [INFO] |  |  |  |  \- aopalliance:aopalliance:jar:1.0:compile
    [INFO] |  |  |  +- org.apache.geronimo.specs:geronimo-stax-api_1.0_spec:jar:1.0.1:compile
    [INFO] |  |  |  \- commons-lang:commons-lang:jar:2.4:compile
    [INFO] |  |  +- javax.xml.soap:saaj-api:jar:1.3:compile
    [INFO] |  |  \- org.bouncycastle:bcprov-jdk15:jar:1.43:runtime
    [INFO] |  +- org.apache.cxf:cxf-rt-frontend-jaxws:jar:2.2.5:compile
    [INFO] |  |  +- xml-resolver:xml-resolver:jar:1.2:compile
    [INFO] |  |  +- org.apache.geronimo.specs:geronimo-jaxws_2.1_spec:jar:1.0:compile
    [INFO] |  |  +- org.apache.geronimo.specs:geronimo-ws-metadata_2.0_spec:jar:1.1.2:compile
    [INFO] |  |  +- asm:asm:jar:2.2.3:compile
    [INFO] |  |  +- org.apache.cxf:cxf-rt-bindings-xml:jar:2.2.5:compile
    [INFO] |  |  +- org.apache.cxf:cxf-rt-frontend-simple:jar:2.2.5:compile
    [INFO] |  |  +- org.apache.cxf:cxf-rt-ws-addr:jar:2.2.5:compile
    [INFO] |  |  \- com.sun.xml.messaging.saaj:saaj-impl:jar:1.3.2:compile
    [INFO] |  +- org.apache.cxf:cxf-rt-transports-http:jar:2.2.5:compile
    [INFO] |  |  \- org.springframework:spring-web:jar:2.5.5:compile
    [INFO] |  \- org.apache.cxf:cxf-rt-transports-http-jetty:jar:2.2.5:compile
    [INFO] |     \- org.apache.geronimo.specs:geronimo-servlet_2.5_spec:jar:1.2:compile
   [INFO] +- javax.servlet:javax.servlet-api:jar:3.1.0:compile
   [INFO] +- net.es.oscars:oscars-war:war:0.0.1-SNAPSHOT:provided
   [INFO] +- org.slf4j:slf4j-api:jar:1.7.7:compile
   [INFO] +- org.slf4j:slf4j-log4j12:jar:1.7.7:compile
   [INFO] +- org.eclipse.jetty:jetty-server:jar:9.3.0.M0:compile
   [INFO] |  +- org.eclipse.jetty:jetty-http:jar:9.3.0.M0:compile
   [INFO] |  |  \- org.eclipse.jetty:jetty-util:jar:9.3.0.M0:compile
   [INFO] |  \- org.eclipse.jetty:jetty-io:jar:9.3.0.M0:compile
   [INFO] +- org.eclipse.jetty:jetty-webapp:jar:9.3.0.M0:compile
   [INFO] |  \- org.eclipse.jetty:jetty-xml:jar:9.3.0.M0:compile
   [INFO] \- org.eclipse.jetty:jetty-servlet:jar:9.3.0.M0:compile
    [INFO]    \- org.eclipse.jetty:jetty-security:jar:9.3.0.M0:compile
   [INFO]   ------------------------------------------------------------------------
   [INFO] BUILD SUCCESS

这是我的pom.xml文件:

<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/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<artifactId>wbui</artifactId>
<name>OSCARS WBUI</name>

<parent>
    <groupId>net.es.oscars</groupId>
    <artifactId>OSCARS</artifactId>
    <version>0.0.1-SNAPSHOT</version>
</parent>

<properties>
    <jetty.version>9.3.0.M0</jetty.version>
</properties>


<!-- puts all code & libraries in one jar -->
<pluginRepositories>
    <pluginRepository>
        <id>onejar-maven-plugin.googlecode.com</id>
        <url>http://onejar-maven-plugin.googlecode.com/svn/mavenrepo</url>
    </pluginRepository>
</pluginRepositories>

<dependencies>
    <!-- OSCARS utilities (from local repository) -->
    <dependency>
        <groupId>net.es.oscars</groupId>
        <artifactId>utils</artifactId>
        <version>${oscars.version}</version>
    </dependency>

    <dependency>
        <groupId>javax.servlet</groupId>
        <artifactId>javax.servlet-api</artifactId>
        <version>3.1.0</version>
    </dependency>

    <!-- kludge to get dependency on local module oscars-war without
         including war file -->
    <dependency>
        <groupId>net.es.oscars</groupId>
        <artifactId>oscars-war</artifactId>
        <version>${oscars.version}</version>
        <type>war</type>
        <scope>provided</scope>
    </dependency>



    <dependency>
        <groupId>org.slf4j</groupId>
        <artifactId>slf4j-api</artifactId>
        <version>1.7.7</version>
    </dependency>
    <dependency>
        <groupId>org.slf4j</groupId>
        <artifactId>slf4j-log4j12</artifactId>
        <version>1.7.7</version>
    </dependency>



    <!--  Jetty -->
    <dependency>
        <groupId>org.eclipse.jetty</groupId>
        <artifactId>jetty-server</artifactId>
        <version>9.3.0.M0</version>
    </dependency>
    <dependency>
        <groupId>org.eclipse.jetty</groupId>
        <artifactId>jetty-webapp</artifactId>
        <version>9.3.0.M0</version>
    </dependency>
    <dependency>
        <groupId>org.eclipse.jetty</groupId>
        <artifactId>jetty-servlet</artifactId>
        <version>9.3.0.M0</version>
    </dependency>

</dependencies>
<build>
    <plugins>
        <!-- puts all code & libraries in one jar -->

        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-shade-plugin</artifactId>
            <version>2.3</version>
            <executions>
                <!-- Run shade goal on package phase -->
                <execution>
                    <phase>package</phase>
                    <goals>
                        <goal>shade</goal>
                    </goals>
                    <configuration>
                        <shadedClassifierName>one-jar</shadedClassifierName>
                        <shadedArtifactAttached>true</shadedArtifactAttached>
                        <filters>
                            <filter>
                                <artifact>*:*</artifact>
                                <excludes>
                                    <exclude>META-INF/*.SF</exclude>
                                    <exclude>META-INF/*.DSA</exclude>
                                    <exclude>META-INF/*.RSA</exclude>
                                </excludes>
                            </filter>
                        </filters>
                        <artifactSet>
                            <excludes>
                                <exclude>org.apache.geronimo.specs:geronimo-servlet_2.5_spec</exclude>
                                <exclude>org.mortbay.jetty:servlet-api</exclude>
                                <exclude>javax.servlet:servlet-api</exclude>
                            </excludes>
                        </artifactSet>
                        <transformers>
                            <!-- add Main-Class to manifest file -->
                            <transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
                                <mainClass>net.es.oscars.wbui.http.WebApp</mainClass>
                            </transformer>
                            <transformer implementation="org.apache.maven.plugins.shade.resource.AppendingTransformer">
                                <resource>META-INF/spring.handlers</resource>
                            </transformer>
                            <transformer implementation="org.apache.maven.plugins.shade.resource.AppendingTransformer">
                                <resource>META-INF/spring.schemas</resource>
                            </transformer>
                            <transformer implementation="org.apache.maven.plugins.shade.resource.AppendingTransformer">
                                <resource>META-INF/services/com.sun.tools.xjc.Plugin</resource>
                            </transformer>
                            <transformer implementation="org.apache.maven.plugins.shade.resource.AppendingTransformer">
                                <resource>META-INF/cxf/cxf.extension</resource>
                            </transformer>
                            <transformer implementation="org.apache.maven.plugins.shade.resource.XmlAppendingTransformer">
                                <resource>META-INF/extensions.xml</resource>
                            </transformer>
                            <transformer implementation="org.apache.maven.plugins.shade.resource.XmlAppendingTransformer">
                                <resource>META-INF/cxf/extensions.xml</resource>
                            </transformer>
                            <transformer implementation="org.apache.maven.plugins.shade.resource.AppendingTransformer">
                                <resource>META-INF/cxf/bus-extensions.txt</resource>
                            </transformer>
                            <transformer implementation="org.apache.maven.plugins.shade.resource.XmlAppendingTransformer">
                                <resource>META-INF/cxf/bus-extensions.xml</resource>
                            </transformer>
                            <transformer implementation="org.apache.maven.plugins.shade.resource.XmlAppendingTransformer">
                                <resource>META-INF/wsdl.plugin.xml</resource>
                            </transformer>
                            <transformer implementation="org.apache.maven.plugins.shade.resource.XmlAppendingTransformer">
                                <resource>META-INF/tools.service.validator.xml</resource>
                            </transformer>
                            <transformer implementation="org.apache.cxf.maven.PluginTransformer">
                                <resource>META-INF/tools-plugin.xml</resource>
                            </transformer>
                            <transformer implementation="org.apache.maven.plugins.shade.resource.XmlAppendingTransformer">
                                <resource>META-INF/cxf/java2wsbeans.xml</resource>
                            </transformer>
                            <transformer implementation="org.apache.cxf.maven.CXFAllTransformer" />
                        </transformers>
                    </configuration>
                </execution>
            </executions>
            <dependencies>
                <dependency>
                    <groupId>org.apache.cxf</groupId>
                    <artifactId>cxf-buildtools</artifactId>
                    <version>2.2.12</version>
                    <type>jar</type>
                    <scope>compile</scope>
                </dependency>
            </dependencies>
        </plugin>
        <!-- specifically use java 1.5 to compile -->
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <configuration>
                <source>${java.version}</source>
                <target>${java.version}</target>
            </configuration>
        </plugin>
    </plugins>
</build>

     package net.es.oscars.wbui.http;

   import java.util.Map;
   import java.io.File;
   import java.io.FileInputStream;

  import org.eclipse.jetty.server.Server;
  import org.eclipse.jetty.webapp.WebAppContext;
  import org.eclipse.jetty.xml.XmlConfiguration;

 import net.es.oscars.utils.config.*;
 import net.es.oscars.utils.svc.ServiceNames;

 public class WebApp {
public static ContextConfig cc = null;

public static void main(String[] args) throws Exception {

    cc = ContextConfig.getInstance(ServiceNames.SVC_WBUI);
    cc.setServiceName(ServiceNames.SVC_WBUI);
    String context = "PRODUCTION";

    if (args.length > 0) {
        context = args[1];
    }
    String warFile = null;
    String warTempDir = null;
    Server server = new Server();

    cc.setContext(context);
    System.setProperty("context",context);
    System.out.println("starting WBUI with context "+ context);
    try {
        cc.loadManifest(ServiceNames.SVC_WBUI,  ConfigDefaults.MANIFEST); // manifest.yaml
        cc.setLog4j();

        String configFile = cc.getFilePath(ConfigDefaults.CONFIG);
        Map config = ConfigHelper.getConfiguration(configFile);
        Map http = (Map) config.get("http");
        warFile = (String) http.get("warFile");
        warTempDir = (String) http.get("warTempDir");
        String jettyConf = cc.getFilePath("jetty.xml");
        XmlConfiguration configuration = new XmlConfiguration(new FileInputStream(jettyConf));
        configuration.configure(server);
    } catch (ConfigException ex) {
        System.out.println("caught ConfigurationException " + ex.getMessage());
        System.exit(-1);
    }
    WebAppContext webapp = new WebAppContext();
    webapp.setContextPath("/OSCARS");
    webapp.setWar(warFile);
    if(warTempDir != null && !warTempDir.equals("")){
        webapp.setTempDirectory(new File(warTempDir));
    }
    server.setHandler(webapp);
    server.start();
    server.join();
}
 }

所以任何想法如何解决这个问题!!!!

1 个答案:

答案 0 :(得分:7)

你的dependency:tree有一个古老的Jetty版本。

org.mortbay.jetty:jetty:jar:6.1.16:compile

那不会起作用。

你需要修复net.es.oscars:utils:jar不要使用那个古老的,早在EOL(End of Life)版本的Jetty。

您的pom.xml引用了不稳定的里程碑版本

<dependency>
    <groupId>org.eclipse.jetty</groupId>
    <artifactId>jetty-server</artifactId>
    <version>9.3.0.M0</version>
</dependency>

使用稳定版本的Jetty。

查看https://www.eclipse.org/jetty/download.html以查看其稳定性(里程碑版本从未列在那里)

另请参阅Jetty文档以了解主要码头版本的总体列表。 https://www.eclipse.org/jetty/documentation/current/what-jetty-version.html

截至本回答时,最新的稳定版本为9.4.18.v20190429

至于java.lang.ClassNotFoundException,您需要先修复您的依赖项。如果在修复依赖项后问题仍然存在,请考虑发布创建类加载器的方式,层次结构以及如何使用XmlConfiguration(以及从哪个类加载器)。