When deploying a webapp using the DeploymentManager
, this error is thrown
2016-06-06 15:19:37,750 WARN [org.eclipse.jetty.deploy.DeploymentManager] (WrapperSimpleAppMain) Unable to reach node goal: started (DeploymentManager.java:506)
java.util.ServiceConfigurationError: javax.servlet.ServletContainerInitializer: Provider org.eclipse.jetty.cdi.websocket.WebSocketCdiInitializer not found
at java.util.ServiceLoader.fail(ServiceLoader.java:239)
at java.util.ServiceLoader.access$300(ServiceLoader.java:185)
at java.util.ServiceLoader$LazyIterator.nextService(ServiceLoader.java:372)
at java.util.ServiceLoader$LazyIterator.next(ServiceLoader.java:404)
at java.util.ServiceLoader$1.next(ServiceLoader.java:480)
at org.eclipse.jetty.annotations.AnnotationConfiguration.getNonExcludedInitializers(AnnotationConfiguration.java:864)
at org.eclipse.jetty.annotations.AnnotationConfiguration.configure(AnnotationConfiguration.java:444)
at org.eclipse.jetty.webapp.WebAppContext.configure(WebAppContext.java:494)
at org.eclipse.jetty.webapp.WebAppContext.startContext(WebAppContext.java:1361)
at org.eclipse.jetty.server.handler.ContextHandler.doStart(ContextHandler.java:772)
at org.eclipse.jetty.servlet.ServletContextHandler.doStart(ServletContextHandler.java:262)
at org.eclipse.jetty.webapp.WebAppContext.doStart(WebAppContext.java:520)
at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:68)
This happens when enabling annotations support using:
org.eclipse.jetty.webapp.Configuration.ClassList classlist = org.eclipse.jetty.webapp.Configuration.ClassList.setServerDefault(server);
classlist.addBefore(
"org.eclipse.jetty.webapp.JettyWebXmlConfiguration",
"org.eclipse.jetty.annotations.AnnotationConfiguration"
);
classlist.addAfter(
"org.eclipse.jetty.webapp.FragmentConfiguration",
"org.eclipse.jetty.plus.webapp.PlusConfiguration"
);
The jar cdi-websocket-9.3.9.v20160517.jar
is in the class path
This issue suggests to deactivate the cdi
Jetty module, but it does not say how to do it with an embedded Jetty.
How do I fix this ?
EDIT
We realize that this issue may be caused by the (complex) environment the application is running in.
Therefore, I am particularly interested in understanding what are the root reasons that could cause this exception to be thrown
CONCLUSION
TD;LR: Jetty-9.3.9 embedded != Jetty-9.3.9 standalone
With Jetty 9.2.14 we were starting jetty programmatically (just like a Jetty embedded) but using the jars of the unpackaged version of a standalone Jetty.
We have had this set-up working fine since Jetty 7 (or maybe even 6) but things started to break when upgrading to Jetty 9.3.9.
Note: we are using Jersey, servlets and a very few JSPs. No websockets. We are upgrading to test HTTP/2.
Since you said you are jetty-embedded, the solution is simple.
Do not include the jetty-cdi-*
jars in your project.
They are not meant to be used from embedded jetty.
Use the cdi-weld
artifacts directly from the weld project for Jetty Embedded.
Be sure you read the weld documentation on how to setup the WebAppClassloader
to allow weld to see the server components. (this is called "punching a hole in the webapp isolation layer")