Java ClassNotFoundException: org.eclipse.jetty.util.component.AbstractLifeCycle 在码头内运行

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/19054286/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-12 13:44:29  来源:igfitidea点击:

ClassNotFoundException: org.eclipse.jetty.util.component.AbstractLifeCycle running inside jetty

javaservletsubuntujetty

提问by erm410

I am having an issue running a servlet in jetty on Ubuntu 13.04. The server is installed using apt-getand started using sudo service jetty start. The app requires the class org.eclipse.jetty.util.component.AbstractLifeCyclebut I get a class not found error. Here is the stack trace:

我在 Ubuntu 13.04 上的 jetty 中运行 servlet 时遇到问题。使用 安装apt-get和启动服务器sudo service jetty start。该应用程序需要该类,org.eclipse.jetty.util.component.AbstractLifeCycle但我收到一个未找到类的错误。这是堆栈跟踪:

java.lang.NoClassDefFoundError: org/eclipse/jetty/util/component/AbstractLifeCycle
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(ClassLoader.java:788)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
at java.net.URLClassLoader.defineClass(URLClassLoader.java:447)
at java.net.URLClassLoader.access0(URLClassLoader.java:71)
at java.net.URLClassLoader.run(URLClassLoader.java:361)
at java.net.URLClassLoader.run(URLClassLoader.java:355)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
at org.eclipse.jetty.webapp.WebAppClassLoader.loadClass(WebAppClassLoader.java:420)
at org.eclipse.jetty.webapp.WebAppClassLoader.loadClass(WebAppClassLoader.java:382)
at org.cometd.server.CometdServlet.newBayeuxServer(CometdServlet.java:130)
at org.cometd.server.CometdServlet.init(CometdServlet.java:64)
at org.cometd.annotation.AnnotationCometdServlet.init(AnnotationCometdServlet.java:54)
at javax.servlet.GenericServlet.init(GenericServlet.java:244)
at org.eclipse.jetty.servlet.ServletHolder.initServlet(ServletHolder.java:542)
at org.eclipse.jetty.servlet.ServletHolder.getServlet(ServletHolder.java:424)
at org.eclipse.jetty.servlet.ServletHolder.handle(ServletHolder.java:671)
at org.eclipse.jetty.servlet.ServletHandler.doHandle(ServletHandler.java:505)
at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:138)
at org.eclipse.jetty.security.SecurityHandler.handle(SecurityHandler.java:564)
at org.eclipse.jetty.server.session.SessionHandler.doHandle(SessionHandler.java:213)
at org.eclipse.jetty.server.handler.ContextHandler.doHandle(ContextHandler.java:1094)
at org.eclipse.jetty.servlet.ServletHandler.doScope(ServletHandler.java:432)
at org.eclipse.jetty.server.session.SessionHandler.doScope(SessionHandler.java:175)
at org.eclipse.jetty.server.handler.ContextHandler.doScope(ContextHandler.java:1028)
at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:136)
at org.eclipse.jetty.server.handler.ContextHandlerCollection.handle(ContextHandlerCollection.java:258)
at org.eclipse.jetty.server.handler.HandlerCollection.handle(HandlerCollection.java:109)
at org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:97)
at org.eclipse.jetty.server.Server.handle(Server.java:445)
at org.eclipse.jetty.server.HttpChannel.handle(HttpChannel.java:267)
at org.eclipse.jetty.server.HttpConnection.onFillable(HttpConnection.java:224)
at org.eclipse.jetty.io.AbstractConnection$ReadCallback.run(AbstractConnection.java:358)
at org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:601)
at org.eclipse.jetty.util.thread.QueuedThreadPool.run(QueuedThreadPool.java:532)
at java.lang.Thread.run(Thread.java:724)
Caused by: java.lang.ClassNotFoundException:          org.eclipse.jetty.util.component.AbstractLifeCycle
at java.net.URLClassLoader.run(URLClassLoader.java:366)
at java.net.URLClassLoader.run(URLClassLoader.java:355)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
at org.eclipse.jetty.webapp.WebAppClassLoader.loadClass(WebAppClassLoader.java:420)
at org.eclipse.jetty.webapp.WebAppClassLoader.loadClass(WebAppClassLoader.java:382)
... 37 more
Caused by:

java.lang.ClassNotFoundException: org.eclipse.jetty.util.component.AbstractLifeCycle
at java.net.URLClassLoader.run(URLClassLoader.java:366)
at java.net.URLClassLoader.run(URLClassLoader.java:355)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
at org.eclipse.jetty.webapp.WebAppClassLoader.loadClass(WebAppClassLoader.java:420)
at org.eclipse.jetty.webapp.WebAppClassLoader.loadClass(WebAppClassLoader.java:382)
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(ClassLoader.java:788)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
at java.net.URLClassLoader.defineClass(URLClassLoader.java:447)
at java.net.URLClassLoader.access0(URLClassLoader.java:71)
at java.net.URLClassLoader.run(URLClassLoader.java:361)
at java.net.URLClassLoader.run(URLClassLoader.java:355)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
at org.eclipse.jetty.webapp.WebAppClassLoader.loadClass(WebAppClassLoader.java:420)
at org.eclipse.jetty.webapp.WebAppClassLoader.loadClass(WebAppClassLoader.java:382)
at org.cometd.server.CometdServlet.newBayeuxServer(CometdServlet.java:130)
at org.cometd.server.CometdServlet.init(CometdServlet.java:64)
at org.cometd.annotation.AnnotationCometdServlet.init(AnnotationCometdServlet.java:54)
at javax.servlet.GenericServlet.init(GenericServlet.java:244)
at org.eclipse.jetty.servlet.ServletHolder.initServlet(ServletHolder.java:542)
at org.eclipse.jetty.servlet.ServletHolder.getServlet(ServletHolder.java:424)
at org.eclipse.jetty.servlet.ServletHolder.handle(ServletHolder.java:671)
at org.eclipse.jetty.servlet.ServletHandler.doHandle(ServletHandler.java:505)
at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:138)
at org.eclipse.jetty.security.SecurityHandler.handle(SecurityHandler.java:564)
at org.eclipse.jetty.server.session.SessionHandler.doHandle(SessionHandler.java:213)
at org.eclipse.jetty.server.handler.ContextHandler.doHandle(ContextHandler.java:1094)
at org.eclipse.jetty.servlet.ServletHandler.doScope(ServletHandler.java:432)
at org.eclipse.jetty.server.session.SessionHandler.doScope(SessionHandler.java:175)
at org.eclipse.jetty.server.handler.ContextHandler.doScope(ContextHandler.java:1028)
at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:136)
at org.eclipse.jetty.server.handler.ContextHandlerCollection.handle(ContextHandlerCollection.java:258)
at org.eclipse.jetty.server.handler.HandlerCollection.handle(HandlerCollection.java:109)
at org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:97)
at org.eclipse.jetty.server.Server.handle(Server.java:445)
at org.eclipse.jetty.server.HttpChannel.handle(HttpChannel.java:267)
at org.eclipse.jetty.server.HttpConnection.onFillable(HttpConnection.java:224)
at org.eclipse.jetty.io.AbstractConnection$ReadCallback.run(AbstractConnection.java:358)
at org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:601)
at org.eclipse.jetty.util.thread.QueuedThreadPool.run(QueuedThreadPool.java:532)
at java.lang.Thread.run(Thread.java:724)

So far I have:

到目前为止,我有:

1) Examined the command used to start jetty to find the classpath using ps:

1)检查用于启动jetty的命令以使用ps查找类路径:

/usr/lib/jvm/java-7-openjdk-amd64/jre/bin/java -Djetty.home=/opt/jetty -Dovc.db_config=/home/ubuntu/ovc/data/ovc-repo/config/sql.properties -Dovc.repo_loc=/home/ubuntu/ovc/data/ovc-repo -cp /opt/jetty/lib/jetty-xml-9.0.4.v20130625.jar:/opt/jetty/lib/servlet-api-3.0.jar:/opt/jetty/lib/jetty-http-9.0.4.v20130625.jar:/opt/jetty/lib/jetty-continuation-9.0.4.v20130625.jar:/opt/jetty/lib/jetty-server-9.0.4.v20130625.jar:/opt/jetty/lib/jetty-security-9.0.4.v20130625.jar:/opt/jetty/lib/jetty-servlet-9.0.4.v20130625.jar:/opt/jetty/lib/jetty-webapp-9.0.4.v20130625.jar:/opt/jetty/lib/jetty-deploy-9.0.4.v20130625.jar:/opt/jetty/lib/jetty-jmx-9.0.4.v20130625.jar:/opt/jetty/lib/jsp/com.sun.el-2.2.0.v201303151357.jar:/opt/jetty/lib/jsp/javax.el-2.2.0.v201303151357.jar:/opt/jetty/lib/jsp/javax.servlet.jsp.jstl-1.2.0.v201105211821.jar:/opt/jetty/lib/jsp/javax.servlet.jsp-2.2.0.v201112011158.jar:/opt/jetty/lib/jsp/org.apache.jasper.glassfish-2.2.2.v201112011158.jar:/opt/jetty/lib/jsp/org.apache.taglibs.standard.glassfish-1.2.0.v201112081803.jar:/opt/jetty/lib/jsp/org.eclipse.jdt.core-3.8.2.v20130121.jar:/opt/jetty/resources:/opt/jetty/lib/websocket/websocket-api-9.0.4.v20130625.jar:/opt/jetty/lib/websocket/websocket-client-9.0.4.v20130625.jar:/opt/jetty/lib/websocket/websocket-common-9.0.4.v20130625.jar:/opt/jetty/lib/websocket/websocket-server-9.0.4.v20130625.jar:/opt/jetty/lib/websocket/websocket-servlet-9.0.4.v20130625.jar:/opt/jetty/lib/jetty-util-9.0.4.v20130625.jar:/opt/jetty/lib/jetty-io-9.0.4.v20130625.jar org.eclipse.jetty.xml.XmlConfiguration /tmp/start2620351902332669076.properties /opt/jetty/etc/jetty.xml /opt/jetty/etc/jetty-jmx.xml /opt/jetty/etc/jetty-http.xml /opt/jetty/etc/jetty-deploy.xml /opt/jetty/etc/jetty-logging.xml /opt/jetty/etc/jetty-started.xml

2) Inspected the jar that should contain the missing class:

2)检查应该包含缺少的类的jar:

~$ jar -tf /opt/jetty/lib/jetty-util-9.0.4.v20130625.jar | grep AbstractLife
org/eclipse/jetty/util/component/AbstractLifeCycle$AbstractLifeCycleListener.class
org/eclipse/jetty/util/component/AbstractLifeCycle.class

Can anyone give a suggestion as to what to check next, I am out of ideas? Thank you.

任何人都可以就接下来要检查的内容提出建议,我没有想法吗?谢谢你。

采纳答案by Joakim Erdfelt

Put the jetty-util-9.0.4.v20130625.jarin your webapp's WEB-INF/lib/

jetty-util-9.0.4.v20130625.jar你的webapp的WEB-INF/lib/

As you can see from the stacktrace, you are attempting to use a class found in jetty-util, from within a webapp.

正如您从堆栈跟踪中看到的那样,您正在尝试从 web 应用程序中使用在 jetty-util 中找到的类。

at org.eclipse.jetty.webapp.WebAppClassLoader.loadClass(WebAppClassLoader.java:420)

This tells you that the webappneeds the class from jetty-util.

这告诉您web 应用程序需要来自 jetty-util 的类。

Because of webapp classloader isolation, and various rules within Jetty, the classes for org.eclipse.jetty.util.*are not provided by the server, and must be provided by the webapp's own WEB-INF/libdirectory.

由于 webapp 类加载器的隔离,以及Jetty 内部的各种规则,for 的类org.eclipse.jetty.util.*不是由服务器提供的,必须由 webapp 自己的WEB-INF/lib目录提供。

回答by Florian

Put the following into your webapps/YOURWAR.xml, within the <Configure class="org.eclipse.jetty.webapp.WebAppContext">(the -in front of org.eclipse.jetty.util.is important):

将以下内容放入您的webapps/YOURWAR.xml, 内<Configure class="org.eclipse.jetty.webapp.WebAppContext">-前面org.eclipse.jetty.util.很重要):

<Call name="prependServerClass">
  <Arg>-org.eclipse.jetty.util.</Arg>
</Call>

You need to prepend it, because the order is important and the last one which is added by default is org.eclipse.jetty.as documented on eclipse.org. So calling addServerClass would be a no-op, as org.eclipse.jetty.util.is already be excluded by org.eclipse.jetty..

您需要预先添加它,因为顺序很重要,并且默认添加的最后一个顺序org.eclipse.jetty.eclipse.org 上所述。因此调用addServerClass将是一个空操作,因为org.eclipse.jetty.util.已经被排除在外org.eclipse.jetty.

回答by Hailong Cao

Joakim Erdfelt pointed the cause, in case anyone needs a snip of pom code, put this in pom file:

Joakim Erdfelt 指出了原因,如果有人需要一段 pom 代码,请将其放在 pom 文件中:

<dependency>
  <groupId>org.eclipse.jetty</groupId>
  <artifactId>jetty-util</artifactId>
  <version>9.3.6.v20151106</version>
</dependency>

回答by taojigu

In deployment environment, just make sure your server classpath has included the Spring jar library (e.g spring-2.5.6.jar).

在部署环境中,只需确保您的服务器类路径已包含 Spring jar 库(例如 spring-2.5.6.jar)。

For Spring3, ContextLoaderListener is moved to spring-web.jar, you can get the library from Maven central repository.

对于 Spring3,ContextLoaderListener 被移动到 spring-web.jar,您可以从 Maven 中央存储库中获取该库。

<dependency>
    <groupId>org.springframework</groupId>
    <artifactId>spring-web</artifactId>
    <version>3.0.5.RELEASE</version>
</dependency>

http://www.mkyong.com/spring/spring-error-classnotfoundexception-org-springframework-web-context-contextloaderlistener/

http://www.mkyong.com/spring/spring-error-classnotfoundexception-org-springframework-web-context-contextloaderlistener/

回答by Peter Isberg

I got this when combining wiremock and DynamoDBLocal which both includes different versions of jetty. Excluding these dependencies in each of these and then explicitly having these in the pom with a specific version. However, seems org.eclipse.jetty.util.component.AbstractLifeCycle is only used in up to version 8.2.0.v20160908 (hence it does not solve it to have a newer version)

我在结合 wiremock 和 DynamoDBLocal 时得到了这个,它们都包含不同版本的码头。在其中的每一个中排除这些依赖项,然后在具有特定版本的 pom 中明确地包含这些依赖项。但是,似乎 org.eclipse.jetty.util.component.AbstractLifeCycle 仅用于最高版本 8.2.0.v20160908 (因此它不能解决它拥有更新版本)

See example below:

请参阅下面的示例:

<properties>
    <jetty.version>8.2.0.v20160908</jetty.version>
</properties>

    <dependency>
        <groupId>com.amazonaws</groupId>
        <artifactId>DynamoDBLocal</artifactId>
        <version>${dynamodb-local.version}</version>
        <scope>test</scope>
        <exclusions>
            <exclusion>
              <groupId>org.eclipse.jetty</groupId>
              <artifactId>jetty-util</artifactId>
            </exclusion>
           <exclusion>
             <groupId>org.eclipse.jetty</groupId>
             <artifactId>jetty-io</artifactId>
           </exclusion>
            <exclusion>
             <groupId>org.eclipse.jetty</groupId>
             <artifactId>jetty-security</artifactId>
           </exclusion>
           <exclusion>
             <groupId>org.eclipse.jetty</groupId>
             <artifactId>jetty-servlets</artifactId>
           </exclusion>
           <exclusion>
             <groupId>org.eclipse.jetty</groupId>
             <artifactId>jetty-webapp</artifactId>
           </exclusion>
           <exclusion>
             <groupId>org.eclipse.jetty</groupId>
             <artifactId>jetty-webapp</artifactId>
           </exclusion>
           <exclusion>
             <groupId>org.eclipse.jetty</groupId>
             <artifactId>jetty-xml</artifactId>
           </exclusion>
        </exclusions>
    </dependency>

    <dependency>
        <groupId>com.github.tomakehurst</groupId>
        <artifactId>wiremock</artifactId>
        <exclusions>
          <exclusion>
            <groupId>com.google.guava</groupId>
            <artifactId>guava</artifactId>
          </exclusion>
           <exclusion>
             <groupId>org.eclipse.jetty</groupId>
             <artifactId>jetty-util</artifactId>
           </exclusion>
           <exclusion>
             <groupId>org.eclipse.jetty</groupId>
             <artifactId>jetty-io</artifactId>
           </exclusion>
            <exclusion>
             <groupId>org.eclipse.jetty</groupId>
             <artifactId>jetty-security</artifactId>
           </exclusion>
           <exclusion>
             <groupId>org.eclipse.jetty</groupId>
             <artifactId>jetty-servlets</artifactId>
           </exclusion>
           <exclusion>
             <groupId>org.eclipse.jetty</groupId>
             <artifactId>jetty-webapp</artifactId>
           </exclusion>
           <exclusion>
             <groupId>org.eclipse.jetty</groupId>
             <artifactId>jetty-webapp</artifactId>
           </exclusion>
           <exclusion>
             <groupId>org.eclipse.jetty</groupId>
             <artifactId>jetty-xml</artifactId>
           </exclusion>
       </exclusions> 
        <version>${wiremock.version}</version>
        <scope>test</scope>
    </dependency>

    <dependency>
      <groupId>org.eclipse.jetty</groupId>
      <artifactId>jetty-util</artifactId>
      <version>${jetty.version}</version>
      <scope>test</scope>
    </dependency>
    <dependency>
      <groupId>org.eclipse.jetty</groupId>
      <artifactId>jetty-io</artifactId>
      <version>${jetty.version}</version>
      <scope>test</scope>
    </dependency>
    <dependency>
      <groupId>org.eclipse.jetty</groupId>
      <artifactId>jetty-security</artifactId>
      <version>${jetty.version}</version>
      <scope>test</scope>
    </dependency>
    <dependency>
      <groupId>org.eclipse.jetty</groupId>
      <artifactId>jetty-servlets</artifactId>
      <version>${jetty.version}</version>
      <scope>test</scope>
    </dependency> 
    <dependency>
      <groupId>org.eclipse.jetty</groupId>
      <artifactId>jetty-webapp</artifactId>
      <version>${jetty.version}</version>
      <scope>test</scope>
    </dependency>       
    <dependency>
      <groupId>org.eclipse.jetty</groupId>
      <artifactId>jetty-xml</artifactId>
      <version>${jetty.version}</version>
      <scope>test</scope>
    </dependency>