1

Dear Stack Overflow Geeks,

I'm trying to create a very basic Java client-server app using Java EE 7 and the intention is to send a message via websocket using JSR 356 implementation.

I've programmed and deployed the server successfully following various blogs I've found out there and I was able to communicate a Javascript client with my java server.

Now what I'm trying to do is to create an standalone java app that needs to communicate with the server and retrieve the same info. I read that JSR 356 implementation can be used in Java clients and that's exactly what I did. I also used Tyrus to create the client and keep it running using the latch mechanism, etc etc etc. Beautiful. The client is finally programmed, the server is up and running BUT when I try to run the client I get this error:

java.lang.reflect.InvocationTargetException
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:601)
at org.glassfish.appclient.client.acc.AppClientContainer.launch(AppClientContainer.java:446)
at org.glassfish.appclient.client.AppClientFacade.main(AppClientFacade.java:166)
Caused by: java.lang.NoClassDefFoundError: javax/websocket/CloseReason$CloseCode
at Main.Main.main(Main.java:27)
... 6 more
Caused by: java.lang.ClassNotFoundException: javax.websocket.CloseReason$CloseCode
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 org.glassfish.appclient.client.acc.ACCClassLoader.findClass(ACCClassLoader.java:237)
at java.lang.ClassLoader.loadClass(ClassLoader.java:423)
at java.lang.ClassLoader.loadClass(ClassLoader.java:356)
... 7 more
Java Result: 1

I'm using Java EE 7 API + Tyrus in NetBeans 7.3 and deploying in a Glassfish 4 (which, from what I've read supports JSR 356 implementation) Now, why on earth is not finding the CloseReason class! :( It should not have compiled if that's the case, isn't it?

Weird thing is that is not complaining about other classes related to websocket implementation (JSR 356) and, on the other hand, I deployed the server (web-app) and the websocket mechanism is working just fine. (I think I didn't implement the CloseReason there though.. but why it's complaining only about that! :@ )

Any help provided will be much appreciated!!

Cheers,

Another Stack Overflow Geek seeking for help. :)

1 Answer 1

1

I'd say its totally impossible to only analyze that stack trace and give you an "answer". At least you should include some code snippets from your project.

Okay, what I think can be the problem is this: The Tyrus libraries are not distributed with the Application Client Container. Locally then, first class that the class loader wants to load.. will fail.

So, right-click your project and select Properties. Select Libraries. Make sure your library has been put beneath the Run tab. If not, click on the Add Library... button you find in this tab and follow procedure!

Hope this was of help to you. If not, review this tutorial on how to package a JavaFX client and have him launched through Java Web Start. The application client in this tutorial depends on external libraries too and you might find something useful in there.

2
  • Thank you Martin for your answer! Now, I added the Tyrus library to the Run tab but it didn't work either. Notice that Tyrus is already added in Compile tab and in the Run tab it says: Compiled Sources, meaning (I believe) that it is already taking them into account. Weird thing is that CloseReason is not the first class the class loader should load because I've instantiated other websocket classes before like Session, EndpointConfig etc. And it's not saying to me: I couldn't find those classes. At compilation time it works perfectly, but when I run, the class loader complains.
    – cSn
    Aug 22, 2013 at 14:52
  • The Application Client Container should include the Websocket API when it distributes the client stubs. Unless your application is using implementation-specific APIs from Tyrus, there's no need to package the Tyrus JAR.
    – Ian Evans
    Aug 22, 2013 at 19:09

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.