Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Strange error when connecting with websocket #1039

Open
schneiderbruno opened this issue Oct 7, 2024 · 1 comment
Open

Strange error when connecting with websocket #1039

schneiderbruno opened this issue Oct 7, 2024 · 1 comment

Comments

@schneiderbruno
Copy link

schneiderbruno commented Oct 7, 2024

I have a very strange error.
When trying to run AblyRealtime realtime = new AblyRealtime(options);

If I run my project by importing the jar manually, I get the error below.
If I run it via Gradle, the error does not occur. However, when I export the jar via Gradle and run the app.jar, the error also occurs...

Exception in thread "Thread-1" java.lang.NoClassDefFoundError: org/java_websocket/exceptions/WebsocketNotConnectedException at io.ably.lib.transport.WebSocketTransport$Factory.getTransport(WebSocketTransport.java:39) at io.ably.lib.transport.WebSocketTransport$Factory.getTransport(WebSocketTransport.java:36) at io.ably.lib.transport.ConnectionManager.connectImpl(ConnectionManager.java:1518) at io.ably.lib.transport.ConnectionManager.access$400(ConnectionManager.java:38) at io.ably.lib.transport.ConnectionManager$Connecting.enact(ConnectionManager.java:227) at io.ably.lib.transport.ConnectionManager$StateChangeAction.enactState(ConnectionManager.java:572) at io.ably.lib.transport.ConnectionManager$AsynchronousStateChangeAction.run(ConnectionManager.java:616) at io.ably.lib.transport.ConnectionManager$ActionHandler.run(ConnectionManager.java:726) at java.base/java.lang.Thread.run(Thread.java:835) Caused by: java.lang.ClassNotFoundException: org.java_websocket.exceptions.WebsocketNotConnectedException at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:583) at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:178) at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:521) ... 9 more

Source code
ClientOptions options = new ClientOptions(XXXX);
AblyRealtime realtime = new AblyRealtime(options);

@ttypic
Copy link
Contributor

ttypic commented Oct 8, 2024

Hey @schneiderbruno,

Is this issue related to #1037? If you look at the error message, it says that your ClassLoader can’t find a runtime dependency.

I reviewed the Gradle file you provided in #1037, and it contains a logical problem. When you try to build a ‘fat’ JAR, you are adding compile dependencies. Compile dependencies are only used during the compilation phase, but to run your JAR file, you need to include runtime dependencies. So instead of:

from { 
    configurations.compileClasspath.collect { it.isDirectory() ? it : zipTree(it) } 
}

you should have:

from { configurations.runtimeClasspath.collect { it.isDirectory() ? it : zipTree(it) } }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

2 participants