I am using jetty as a embedded Server in eclipse. It keep throwing ClassNotFoundException when start the server.
Stack track looks like:
Failed startup of context o.e.j.w.WebAppContext@6561e97d{/,null,UNAVAILABLE}
java.lang.ClassNotFoundException: org.eclipse.jetty.webapp.WebInfConfiguration
at java.net.URLClassLoader.findClass(URLClassLoader.java:609)
at java.lang.ClassLoader.loadClassHelper(ClassLoader.java:925)
at java.lang.ClassLoader.loadClass(ClassLoader.java:870)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:343)
at java.lang.ClassLoader.loadClass(ClassLoader.java:853)
at org.eclipse.osgi.internal.framework.ContextFinder.loadClass(ContextFinder.java:132)
at java.lang.ClassLoader.loadClass(ClassLoader.java:853)
at org.eclipse.jetty.util.Loader.loadClass(Loader.java:65)
at org.eclipse.jetty.webapp.WebAppContext.loadConfigurations(WebAppContext.java:1035)
at org.eclipse.jetty.webapp.WebAppContext.preConfigure(WebAppContext.java:473)
at org.eclipse.jetty.webapp.WebAppContext.doStart(WebAppContext.java:544)
at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:68)
at org.eclipse.jetty.util.component.ContainerLifeCycle.start(ContainerLifeCycle.java:138)
at org.eclipse.jetty.server.Server.start(Server.java:419)
at org.eclipse.jetty.util.component.ContainerLifeCycle.doStart(ContainerLifeCycle.java:108)
at org.eclipse.jetty.server.handler.AbstractHandler.doStart(AbstractHandler.java:113)
at org.eclipse.jetty.server.Server.doStart(Server.java:386)
at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:68)
My code is quite simple:
Server server = new Server(8080)
WebAppContext context = new WebAppContext();
..........
context.addServlet(xxxx);
............
server.start();
I tried different versions of jetty. It does not work on jetty 9.4.10 either but works fine without any exception on jetty 9.3.8.
@0Steve0 dude, you did not even provide a stack trace, nor the name of the class that was not found.
99% is a missing jar on your side, so please try harder on your side first and if you still have a problem provide detailed information.
@sbordet sorry mate, forgot to update my description.
@0Steve0 what is your classpath? List at least Jetty's jars.
You obviously have a strange environment.
Your environment obviously loaded org.eclipse.jetty.webapp.WebAppContext, but couldn't load org.eclipse.jetty.webapp.WebInfConfiguration from the same jetty-webapp-<version>.jar??
The only time I've seen this is when using OSGi and/or an IBM JVM.
@joakime you are right, i am using OSGI
I found a similar issue here: https://github.com/eclipse/jetty.project/issues/705.
@0Steve0 make sure you have and use Apache SpiFly with your OSGi environment. (it's a requirement for ServiceLoader functionality)
@0Steve0 also, you'll have nearly no luck using standard techniques and behaviors with OSGi.
The entire jetty-osgi tree exists to work around the deficiencies and bad assumptions in OSGi.
See: https://github.com/eclipse/jetty.project/tree/jetty-9.4.x/jetty-osgi
Probably need to start at jetty-osgi-boot .
If you want to use JSP, you have different OSGi hack you need to use.
If you want to use ALPN and HTTP/2 you have a different OSGi hack you need to use.
If you want annotations to work, you have a different OSGi hack to use.
In short, you'll have a tremendous amount of boilerplate code to "setup" of the OSGi environment, along with special one-off classes of existing Jetty classes you'll need to use just because of your choice of OSGi.
@joakime By reading through https://github.com/eclipse/jetty.project/issues/705, i found a potential fix for this issue, just add Thread.currentThread().setContextClassLoader(MY_SERVER_CLASS.class.getClassLoader()); before server.Start();
Most helpful comment
@0Steve0 dude, you did not even provide a stack trace, nor the name of the class that was not found.
99% is a missing jar on your side, so please try harder on your side first and if you still have a problem provide detailed information.