[
Date Prev][
Date Next][
Thread Prev][
Thread Next][
Date Index][
Thread Index]
[
List Home]
[jetty-dev] Classloader problem with jetty 9.2.22
|
Hi,
I have some classpath problems using
org.eclipse.jetty.util.ssl.SslContextFactory
as part of a
org.eclipse.jetty.websocket.client.WebSocketClient
from within a web application as in
SslContextFactory sslContextFactory = new SslContextFactory();
WebSocketClient webSocketClient = new WebSocketClient(sslContextFactory);
I think I'm on the wrong track to find a solution for this, maybe someone can lead me to the right direction how to configure jetty for this.
I have attached a maven project with the code from above, the class SimpleServlet contains the relevant code.
When I bundle
jetty-util-9.2.22.v20170606.jar
with the web application, accessing the servlet leads to
java.lang.LinkageError: loader constraint violation: when resolving method "org.eclipse.jetty.websocket.client.WebSocketClient.<init>(Lorg/eclipse/jetty/util/ssl/SslContextFactory;)V" the class loader (instance of org/eclipse/jetty/webapp/WebAppClassLoader) of the current class, com/test/SimpleServlet, and the class loader (instance of org/eclipse/jetty/start/Classpath$Loader) for the method's defining class, org/eclipse/jetty/websocket/client/WebSocketClient, have different Class objects for the type org/eclipse/jetty/util/ssl/SslContextFactory used in the signature
So instead I removed the library from the web application to get the one already provided by jetty, but then I get
java.lang.NoClassDefFoundError: org/eclipse/jetty/util/ssl/SslContextFactory
...
Caused by: java.lang.ClassNotFoundException: org.eclipse.jetty.util.ssl.SslContextFactory
Lession learned, I need to make it accessible as server class, for which I first tried to adopt the configuration as follows:
I added to my context definition as part of 'org.eclipse.jetty.webapp.WebAppContext':
<Set name="parentLoaderPriority">true</Set>
<Call name="addServerClass">
<Arg>-org.eclipse.jetty.util.</Arg>
</Call>
This did not help. I think because this method adds the argument to the end of the list, but as the list of classes during runtime is not using a best-match but a first-match and "org.eclipse.jetty." is first, my addition of
"-org.eclipse.jetty.util." was not respected at all.
As next try I removed the 'addServerClass' from the WebAppContext-definition and changed jetty-deploy.xml instead.
I added
<Call name="setAttribute">
<Arg>org.eclipse.jetty.webapp.serverClasses</Arg>
<Arg>
<Array type="java.lang.String">
<Item>-org.eclipse.jetty.util.ssl.</Item>
<Item>-org.eclipse.jetty.jmx.</Item>
<Item>-org.eclipse.jetty.util.annotation.</Item>
<Item>-org.eclipse.jetty.continuation.</Item>
<Item>-org.eclipse.jetty.jndi.</Item>
<Item>-org.eclipse.jetty.jaas.</Item>
<Item>-org.eclipse.jetty.servlets.</Item>
<Item>-org.eclipse.jetty.servlet.DefaultServlet</Item>
<Item>-org.eclipse.jetty.jsp.</Item>
<Item>-org.eclipse.jetty.servlet.listener.</Item>
<Item>-org.eclipse.jetty.websocket.</Item>
<Item>-org.eclipse.jetty.apache.</Item>
<Item>-org.eclipse.jetty.util.log.</Item>
<Item>-org.eclipse.jetty.servlet.ServletContextHandler.Decorator</Item>
<Item>org.objectweb.asm.</Item>
<Item>org.eclipse.jdt.</Item>
<Item>org.eclipse.jetty.</Item>
</Array>
</Arg>
</Call>
This in the end worked, but I wonder if this is the right way to go to change the whole server configuration just to make SslSocketFactory available to one single web application.
In the end I would prefer to leave
jetty-util-9.2.22.v20170606.jar
within the web application and correctly separate the class loaders so that I can use WebSocketClient and SslContextFactory from a web application.
Any ideas what I am missing here?
Best Regards,
Christian
Attachment:
SimpleServlet.zip
Description: Zip archive