嵌入式码头 java.lang.NoClassDefFoundError: org/mortbay/log/Log

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/20405527/
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-13 01:43:50  来源:igfitidea点击:

Embedded Jetty java.lang.NoClassDefFoundError: org/mortbay/log/Log

javajettyembedded-jetty

提问by Todd Chapman

I'm trying to write a small embedded Jetty program for an app that is normally deployed to Tomcat. My app appears to initialize fine but then the Jetty server start throws an error related to logging. I have a log4j.properties file in my src directory and am including log4j and slf4j-log4j12 as Maven dependencies. Any idea where I've erred?

我正在尝试为通常部署到 Tomcat 的应用程序编写一个小的嵌入式 Jetty 程序。我的应用程序似乎初始化良好,但随后 Jetty 服务器启动引发与日志记录相关的错误。我的 src 目录中有一个 log4j.properties 文件,并且包含 log4j 和 slf4j-log4j12 作为 Maven 依赖项。知道我哪里出错了吗?

Thanks!

谢谢!

WARN - FAILED org.eclipse.jetty.server.Server@6b0e9064: java.lang.NoClassDefFoundError: org/mortbay/log/Log
java.lang.NoClassDefFoundError: org/mortbay/log/Log
    at com.sun.org.apache.commons.logging.JettyLog.<init>(JettyLog.java:36)
    at com.sun.org.apache.commons.logging.LogFactory.getLog(LogFactory.java:35)
    at org.apache.jasper.servlet.JspServlet.<clinit>(JspServlet.java:116)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57)
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
    at java.lang.reflect.Constructor.newInstance(Constructor.java:525)
    at java.lang.Class.newInstance0(Class.java:374)
    at java.lang.Class.newInstance(Class.java:327)
    at org.eclipse.jetty.server.handler.ContextHandler$Context.createInstance(ContextHandler.java:2307)
    at org.eclipse.jetty.servlet.ServletContextHandler$Context.createInstance(ServletContextHandler.java:1164)
    at org.eclipse.jetty.servlet.ServletContextHandler$Context.createServlet(ServletContextHandler.java:1151)
    at org.eclipse.jetty.servlet.ServletHolder.newInstance(ServletHolder.java:976)
    at org.eclipse.jetty.servlet.ServletHolder.initServlet(ServletHolder.java:521)
    at org.eclipse.jetty.servlet.ServletHolder.initialize(ServletHolder.java:349)
    at org.eclipse.jetty.servlet.ServletHandler.initialize(ServletHandler.java:810)
    at org.eclipse.jetty.servlet.ServletContextHandler.startContext(ServletContextHandler.java:288)
    at org.eclipse.jetty.webapp.WebAppContext.startContext(WebAppContext.java:1346)
    at org.eclipse.jetty.server.handler.ContextHandler.doStart(ContextHandler.java:743)
    at org.eclipse.jetty.webapp.WebAppContext.doStart(WebAppContext.java:491)
    at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:69)
    at org.eclipse.jetty.util.component.ContainerLifeCycle.start(ContainerLifeCycle.java:117)
    at org.eclipse.jetty.util.component.ContainerLifeCycle.doStart(ContainerLifeCycle.java:99)
    at org.eclipse.jetty.server.handler.AbstractHandler.doStart(AbstractHandler.java:60)
    at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:69)
    at org.eclipse.jetty.util.component.ContainerLifeCycle.start(ContainerLifeCycle.java:117)
    at org.eclipse.jetty.server.Server.start(Server.java:355)
    at org.eclipse.jetty.util.component.ContainerLifeCycle.doStart(ContainerLifeCycle.java:99)
    at org.eclipse.jetty.server.handler.AbstractHandler.doStart(AbstractHandler.java:60)
    at org.eclipse.jetty.server.Server.doStart(Server.java:324)
    at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:69)
    at com.foo.rscontrolcenter.ControlCenter.main(ControlCenter.java:19)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:601)
    at com.intellij.rt.execution.application.AppMain.main(AppMain.java:120)

Here is my program:

这是我的程序:

public class ControlCenter {

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

        Server server = new Server( 8080 );
        WebAppContext root = new WebAppContext("ControlCenter/Website/", "/controlcenter");
        HandlerCollection handlerCollection = new HandlerCollection();

        handlerCollection.addHandler(root);

        server.setHandler(handlerCollection);
        server.start();
    }

}

采纳答案by Joakim Erdfelt

You choose the wrong JspServlet implementation.

您选择了错误的 JspServlet 实现。

It is looking for org.mortbay.jettybased classes, that's for Old Jetty 6 and earlier.

它正在寻找适用org.mortbay.jetty于 Old Jetty 6 及更早版本的类。

The Example Project

示例项目

Look at the jetty-project/embedded-jetty-jspexample on github for a working example of embedded jetty + jsp support.

查看jetty-project/embedded-jetty-jspgithub 上的示例,了解嵌入式 jetty + jsp 支持的工作示例。

https://github.com/jetty-project/embedded-jetty-jsp

https://github.com/jetty-project/embedded-jetty-jsp

Pay attention to:

注意:

The Dependencies

依赖关系

Here's the dependency tree in use by that example project

这是该示例项目使用的依赖树

[embedded-jetty-jsp]$ mvn dependency:tree
[INFO] Scanning for projects...
[INFO]                                                                         
[INFO] ------------------------------------------------------------------------
[INFO] Building embedded-jetty-jsp 1-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO] 
[INFO] --- maven-dependency-plugin:2.1:tree (default-cli) @ embedded-jetty-jsp ---
[INFO] org.eclipse.jetty.demo:embedded-jetty-jsp:jar:1-SNAPSHOT
[INFO] +- javax.servlet:javax.servlet-api:jar:3.1.0:compile
[INFO] +- org.eclipse.jetty:jetty-webapp:jar:9.1.0.v20131115:compile
[INFO] |  +- org.eclipse.jetty:jetty-xml:jar:9.1.0.v20131115:compile
[INFO] |  |  \- org.eclipse.jetty:jetty-util:jar:9.1.0.v20131115:compile
[INFO] |  \- org.eclipse.jetty:jetty-servlet:jar:9.1.0.v20131115:compile
[INFO] |     \- org.eclipse.jetty:jetty-security:jar:9.1.0.v20131115:compile
[INFO] |        \- org.eclipse.jetty:jetty-server:jar:9.1.0.v20131115:compile
[INFO] |           +- org.eclipse.jetty:jetty-http:jar:9.1.0.v20131115:compile
[INFO] |           \- org.eclipse.jetty:jetty-io:jar:9.1.0.v20131115:compile
[INFO] \- org.eclipse.jetty:jetty-jsp:pom:9.1.0.v20131115:compile
[INFO]    +- org.eclipse.jetty.toolchain:jetty-schemas:jar:3.1.M0:compile
[INFO]    +- javax.servlet.jsp:javax.servlet.jsp-api:jar:2.3.1:compile
[INFO]    +- org.glassfish.web:javax.servlet.jsp:jar:2.3.2:compile
[INFO]    +- org.eclipse.jetty.orbit:javax.servlet.jsp.jstl:jar:1.2.0.v201105211821:compile
[INFO]    +- org.eclipse.jetty.orbit:org.apache.taglibs.standard.glassfish:jar:1.2.0.v201112081803:compile
[INFO]    \- org.glassfish:javax.el:jar:3.0.0:compile
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 2.528s
[INFO] Finished at: Thu Dec 05 11:03:49 MST 2013
[INFO] Final Memory: 12M/484M
[INFO] ------------------------------------------------------------------------