質問

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. :)

役に立ちましたか?

解決

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.

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top