gpt4 book ai didi

java - 嵌入式 jetty java.lang.NoClassDefFoundError : org/mortbay/log/Log

转载 作者:搜寻专家 更新时间:2023-10-31 20:34:38 30 4
gpt4 key购买 nike

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

谢谢!

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)

这是我的程序:

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

}

最佳答案

您选择了错误的 JspServlet 实现。

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

示例项目

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

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

注意:

依赖关系

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

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

关于java - 嵌入式 jetty java.lang.NoClassDefFoundError : org/mortbay/log/Log,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20405527/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com