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

时间:2013-09-27 15:15:28

标签: java servlets ubuntu jetty

我遇到了在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.access$100(URLClassLoader.java:71)
at java.net.URLClassLoader$1.run(URLClassLoader.java:361)
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 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$3.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$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 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$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 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.access$100(URLClassLoader.java:71)
at java.net.URLClassLoader$1.run(URLClassLoader.java:361)
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 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$3.run(QueuedThreadPool.java:532)
at java.lang.Thread.run(Thread.java:724)

到目前为止,我有:

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)检查了应该包含缺失类的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

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

5 个答案:

答案 0 :(得分:7)

jetty-util-9.0.4.v20130625.jar放入您的网络应用WEB-INF/lib/

从堆栈跟踪中可以看出,您正试图在webapp中使用jetty-util中的类。

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

这告诉您 webapp 需要来自jetty-util的类。

由于webapp类加载器隔离和various rules within Jetty,服务器不提供org.eclipse.jetty.util.*的类,并且必须由webapp自己的WEB-INF/lib目录提供。

答案 1 :(得分:1)

将以下内容放入webapps/YOURWAR.xml <Configure class="org.eclipse.jetty.webapp.WebAppContext">- org.eclipse.jetty.util.前面的<Call name="prependServerClass"> <Arg>-org.eclipse.jetty.util.</Arg> </Call>

org.eclipse.jetty.

您需要预先添加它,因为顺序很重要,默认情况下添加的最后一个是org.eclipse.jetty.util.,如eclipse.org所述。所以调用addServerClass将是一个无操作,因为org.eclipse.jetty.已经排除class Program { static void Main(string[] args) { try { string roll ="1"; string fileName = @"D:\demo.txt"; TcpClient tcpClient = new TcpClient("127.0.0.1", 1234); Console.WriteLine("Connected. Sending file."); StreamWriter sWriter = new StreamWriter(tcpClient.GetStream()); byte[] bytes = File.ReadAllBytes(fileName); sWriter.WriteLine(bytes.Length.ToString()); sWriter.Flush(); sWriter.WriteLine(fileName); sWriter.Flush(); Console.WriteLine("Sending file"); tcpClient.Client.SendFile(fileName); } catch (Exception e) { Console.Write(e.Message); } Console.Read(); } }

答案 2 :(得分:1)

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

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

答案 3 :(得分:0)

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

对于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/

答案 4 :(得分:0)

当结合Wiremock和DynamoDBLocal时,我得到了这一点,两者都包含不同版本的码头。在每个依赖项中排除这些依赖项,然后在特定版本的pom中明确包含这些依赖项。然而, 似乎org.eclipse.jetty.util.component.AbstractLifeCycle仅在8.2.0.v20160908以前的版本中使用(因此无法解决它具有更新的版本)

请参见以下示例:

<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>