问题描述
我正在尝试在嵌入式码头服务器上运行我的(接缝和)检票口应用程序.
I'm trying to run my (seam and) wicket app on an embedded jetty server.
我得到以下异常:
Caused by: java.lang.ClassNotFoundException: org.slf4j.LoggerFactory
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at org.mortbay.jetty.webapp.WebAppClassLoader.loadClass(WebAppClassLoader.java:366)
at org.mortbay.jetty.webapp.WebAppClassLoader.loadClass(WebAppClassLoader.java:337)
... 28 more
但是,LoggerFactory类在我的类路径中.我对此进行了如下测试:
However, the LoggerFactory class is on my classpath. I tested this as follows:
public class StartJetty {
public static void main(String[] args) throws Exception {
ILoggerFactory fac = LoggerFactory.getILoggerFactory(); //this works!
Server server = new Server();
...
完成课程:
public class StartJetty {
public static void main(String[] args) throws Exception {
Logger log = LoggerFactory.getLogger(StartJetty.class);
Server server = new Server();
SocketConnector connector = new SocketConnector();
connector.setMaxIdleTime(1000 * 60 * 60);
connector.setSoLingerTime(-1);
connector.setPort(8090);
server.setConnectors(new Connector[] { connector });
WebAppContext bb = new WebAppContext();
bb.setParentLoaderPriority(true);
bb.setServer(server);
bb.setContextPath("/wicket");
bb.setWar("C:/wicket/exploded-archives/wicket.war");
server.setHandler(bb);
try {
server.start();
while (System.in.available() == 0) {
Thread.sleep(1000);
}
server.stop();
server.join();
} catch (Throwable e) {
e.printStackTrace();
System.exit(100);
}
}
}
推荐答案
1-更新为码头7或码头8,从外观上您正在使用码头6,并且在耳后变得越来越白...此时正在使用jetty-9(如果要使用servlet 2.5,请使用jetty7,如果要使用servlet 3.0,请使用jetty8)
1 - update to jetty 7 or jetty 8, your using jetty 6 by the looks of it and that is getting quite gray behind the ears...we are working on jetty-9 at this point (jetty7 if you want servlet 2.5 and jetty8 if you want servlet 3.0 support)
2-一个webapp在隔离的类加载器中执行,因此您看到的是它正常运行,您需要在要创建的webapp上下文中设置父类加载器优先级,或者使用服务器/系统机制来公开这些org.slf4j类.
2 - a webapp executes in an isolated classloader so what you are seeing is that working correctly, you need to set the parent class loader priority on the webapp context that you are creating, or use the server/system mechanism to expose just those org.slf4j classes.
请参见 http://wiki.eclipse.org/Jetty/Reference/Jetty_Classloading 以获得更多有关码头上课的信息.
See http://wiki.eclipse.org/Jetty/Reference/Jetty_Classloading for more information on classloading in jetty.
这篇关于小门和嵌入式码头-classNotFoundException的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!