web-dev-qa-db-ja.com

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

私はmvn installを実行するときにMavenプロジェクトを実行しようとしていますが、すべて問題ありません。

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 dependency: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();
}
 }

この問題を解決する方法はありますか!!!!

6
foucha

あなたのdependency:treeには、Jettyの古いバージョンがあります。

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

それはうまくいきません。

JettyのEOL(End of Life)バージョン以来ずっと、その古いものを使用しないようにnet.es.oscars:utils:jarを修正する必要があります。

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 を見て、安定しているものを確認します(マイルストーンリリースがそこにリストされていない)

主要な突堤バージョンの全体的なリストについては、突堤のドキュメントも参照してください。 https://www.Eclipse.org/jetty/documentation/current/what-jetty-version.html

この回答の時点での最新の安定リリースバージョンは9.4.18.v20190429です。

Java.lang.ClassNotFoundExceptionについては、まず依存関係を修正する必要があります。依存関係を修正しても問題が解決しない場合は、クラスローダーの作成方法とその階層、およびXmlConfigurationの使用方法(およびどのクラスローダーから)を投稿するか検討してください。

7
Joakim Erdfelt