question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

java.lang.NoClassDefFoundError: org/eclipse/jetty/websocket/api/Session

See original GitHub issue

My code is very simple:

public class HtmlUnitDriverTest {
    public static void main(String[] args) {
        final WebClient webClient = new WebClient();
    }
}

When use htmlunit-driver 2.20, it’s ok. But when i update to 2.23, i meet the following error:

Exception in thread “main” java.lang.NoClassDefFoundError: org/eclipse/jetty/websocket/api/Session at java.lang.Class.getDeclaredMethods0(Native Method) at java.lang.Class.privateGetDeclaredMethods(Class.java:2625) at java.lang.Class.getDeclaredMethods(Class.java:1868) at com.gargoylesoftware.htmlunit.javascript.configuration.AbstractJavaScriptConfiguration.process(AbstractJavaScriptConfiguration.java:197) at com.gargoylesoftware.htmlunit.javascript.configuration.AbstractJavaScriptConfiguration.getClassConfiguration(AbstractJavaScriptConfiguration.java:172) at com.gargoylesoftware.htmlunit.javascript.configuration.AbstractJavaScriptConfiguration.buildUsageMap(AbstractJavaScriptConfiguration.java:79) at com.gargoylesoftware.htmlunit.javascript.configuration.AbstractJavaScriptConfiguration.<init>(AbstractJavaScriptConfiguration.java:59) at com.gargoylesoftware.htmlunit.javascript.configuration.JavaScriptConfiguration.<init>(JavaScriptConfiguration.java:597) at com.gargoylesoftware.htmlunit.javascript.configuration.JavaScriptConfiguration.getInstance(JavaScriptConfiguration.java:613) at com.gargoylesoftware.htmlunit.javascript.JavaScriptEngine.<init>(JavaScriptEngine.java:133) at com.gargoylesoftware.htmlunit.WebClient.init(WebClient.java:239) at com.gargoylesoftware.htmlunit.WebClient.<init>(WebClient.java:213) at com.gargoylesoftware.htmlunit.WebClient.<init>(WebClient.java:204) at HtmlUnitDriverTest.main(HtmlUnitDriverTest.java:11) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:606) at com.intellij.rt.execution.application.AppMain.main(AppMain.java:144) Caused by: java.lang.ClassNotFoundException: org.eclipse.jetty.websocket.api.Session at java.net.URLClassLoader$1.run(URLClassLoader.java:366) at java.net.URLClassLoader$1.run(URLClassLoader.java:355) at java.security.AccessController.doPrivileged(Native Method) at java.net.URLClassLoader.findClass(URLClassLoader.java:354) at java.lang.ClassLoader.loadClass(ClassLoader.java:425) at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308) at java.lang.ClassLoader.loadClass(ClassLoader.java:358) … 19 more

I compare my pom.xml file of 2.20 and 2.23, my 2.20 pom:

<dependency>
    <groupId>net.sourceforge.htmlunit</groupId>
    <artifactId>htmlunit</artifactId>
    <version>2.20</version>
</dependency>

the 2.23 pom:

<dependency>
    <groupId>net.sourceforge.htmlunit</groupId>
    <artifactId>htmlunit</artifactId>
    <version>2.23</version>
    <exclusions>
        <exclusion>
            <groupId>org.eclipse.jetty.websocket</groupId>
            <artifactId>websocket-client</artifactId>
        </exclusion>
    </exclusions>
</dependency>

Do I need to manually add the dependency for jetty? Please help me, thanks a lot.

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:9 (2 by maintainers)

github_iconTop GitHub Comments

5reactions
ThrawnCAcommented, Oct 14, 2016

I think I’ve found it!

You haven’t specified the BrowserVersion that your WebClient will emulate, so it defaults to the best-supported version - which is currently Chrome. And when your WebClient initialises its JavaScript support, the configuration class (com.gargoylesoftware.htmlunit.javascript.configuration.AbstractJavaScriptConfiguration, if you’re wondering) will trawl the annotations on all known JavaScript objects (the list is in com.gargoylesoftware.htmlunit.javascript.configuration.JavaScriptConfiguration) to check whether they support the selected BrowserVersion. And WebSocket uses the JsxClass annotation with default values - which support Chrome. So, by default, it will attempt to load WebSocket support.

So yes, you probably should add the websocket-client dependency. I assume that it was dropped so that clients using a different browser version don’t have to include it - although since the default is to rely on it, I’d call that a poor choice. If someone really doesn’t want that JAR, they can specifically exclude it themselves.

0reactions
snicollcommented, Jan 8, 2017

Can you just add the dependency manually, when HtmlUnitDriver is referenced?

No, I don’t use htmlunit but Spring Boot provides auto-configuration for the WebClient. If a user of Spring Boot adds htmlunit on the classpath, we auto-configure the WebClient and it will throw this exception unless websocket-client is manually added. We won’t upgrade until this issue is fixed as we cannot shield our users from this (they add the dependency themselves).

A bug fix release in the coming couple of weeks would be very appreciated.

Read more comments on GitHub >

github_iconTop Results From Across the Web

ClassNotFoundException org.eclipse.jetty.websocket. ...
I finally answered my question by myself. The issue could be resolved by adding the classpaths to the missing jars in the ...
Read more >
org.eclipse.jetty.websocket.server.WebSocketServerFactory
I am trying to follow few Jetty 9 websocket tutorials ( like ... import org.eclipse.jetty.websocket.api. ... private Session mSession;.
Read more >
3 ways to solve java.lang.NoClassDefFoundError in Java ...
I am getting java.lang.NoClassDefFoundError while running my program in Eclipse IDE. I checked the classpath and seems class is there. Eclipse is giving...
Read more >
Maven Repository: org.eclipse.jetty.websocket
org.eclipse.jetty.websocket » javax-websocket-server-implApacheEPL. Javax WebSocket Server Impl ... org.eclipse.jetty.websocket » websocket-apiApacheEPL.
Read more >
跑不起来,说是少了一个jetty 包,但是我有在pom里面配置啊
NoClassDefFoundError : org/eclipse/jetty/io/ManagedSelector$CloseEndPoints at ... doStop(ContainerLifeCycle.java:160) at org.eclipse.jetty.websocket.client.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found