问题
I'm trying to run my (seam and) wicket app on an embedded jetty server.
I get the following exception:
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
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();
...
Complete class:
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:
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 - 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.
See http://wiki.eclipse.org/Jetty/Reference/Jetty_Classloading for more information on classloading in jetty.
回答2:
I found the answer from Martjin Dashorst here is a good advice for debugging: https://stackoverflow.com/a/13413342/1915920
- remove all
*.jar
s fromWEB-INF/lib
to some tmp folder - restart via
service jetty restart
or similar - look at the logs for problems or which classes are found to be missing
- add some jars back (e.g. grouped by type to speed it up ... orm/db-related, ui-related, different functionality-scopes and their dependencies) to the
WEB-INF/lib
folder - repeat 2. to 4. till you likely spot the real conflicting problem
(or none if the conflicting jars are not needed in your
WEB-INF/lib
folder at all (anymore)
applying some class loader related stuff to the web.xml
did not help me there: https://jira.codehaus.org/browse/JETTY-574
来源:https://stackoverflow.com/questions/9821010/wicket-and-embedded-jetty-classnotfoundexception