Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [jetty-dev] Classloader problem with jetty 9.2.22

Different call probably would have worked ...

<Call name="prependServerClass">

Joakim Erdfelt / joakim@xxxxxxxxxxx

On Thu, Sep 21, 2017 at 5:47 AM, Christian Elsen <christian.elsen@xxxxxxxxxxxxxxx> wrote:

I have some classpath problems using
as part of a
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
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">

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">
            <Array type="java.lang.String">

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
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,

jetty-dev mailing list
To change your delivery options, retrieve your password, or unsubscribe from this list, visit

Back to the top