java.lang.NoClassDefFoundError: org/eclipse/jetty/websocket/api/Session
See original GitHub issueMy 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:
- Created 7 years ago
- Comments:9 (2 by maintainers)
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 incom.gargoylesoftware.htmlunit.javascript.configuration.JavaScriptConfiguration
) to check whether they support the selectedBrowserVersion
. AndWebSocket
uses theJsxClass
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.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 theWebClient
and it will throw this exception unlesswebsocket-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.