我正在尝试为通常部署到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();
}
}
答案 0 :(得分:1)
您选择了错误的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] ------------------------------------------------------------------------