Java RMI NoClassDefFoundError for javax.json.JsonValue in Remote object
Asked Answered
A

1

6

Running into Exception caused during call to UnicastRemoteObject.exportObject().

javax.json.jar is on the classpath and is used in many other places in the application without any problems.

This part of the application worked fine until I added a method that returned a JsonValue to the remote object.

Any ideas?

java.rmi.ServerError: Error occurred in server thread; nested exception is: 
    java.lang.NoClassDefFoundError: javax/json/JsonValue
    at sun.rmi.server.UnicastServerRef.oldDispatch(UnicastServerRef.java:416)
    at sun.rmi.server.UnicastServerRef.dispatch(UnicastServerRef.java:267)
    at sun.rmi.transport.Transport$1.run(Transport.java:177)
    at sun.rmi.transport.Transport$1.run(Transport.java:174)
    at java.security.AccessController.doPrivileged(Native Method)
    at sun.rmi.transport.Transport.serviceCall(Transport.java:173)
    at sun.rmi.transport.tcp.TCPTransport.handleMessages(TCPTransport.java:556)
    at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run0(TCPTransport.java:811)
    at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run(TCPTransport.java:670)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
    at java.lang.Thread.run(Thread.java:745)
    at sun.rmi.transport.StreamRemoteCall.exceptionReceivedFromServer(StreamRemoteCall.java:275)
    at sun.rmi.transport.StreamRemoteCall.executeCall(StreamRemoteCall.java:252)
    at sun.rmi.server.UnicastRef.invoke(UnicastRef.java:378)
    at sun.rmi.registry.RegistryImpl_Stub.bind(Unknown Source)

NOTE: I also tried running the rmiregistry with codebase pointed directly at the javax.json.jar but the exception remains

rmiregistry -J-Djava.rmi.server.codebase=file:///JarLibrary/javax.json.jar &
Adeline answered 8/12, 2015 at 0:53 Comment(2)
Could you show us the signature of the method that you added to your remote interface ?Jumada
@QuakeCore: public static JsonValue getJsonValue()Adeline
K
3

Running into Exception caused during call to UnicastRemoteObject.exportObject().

No you aren't. See the stack trace. It's happening in Registry.bind().

You need to run the server with the java.rmi.server.codebase property set, but a file:// codebase URL isn't going to work unless either all the clients are running in the server host, in which case you don't really need the codebase feature at all, or it points to a shared folder in a form that both the Registry and the clients can use. It's usually HTTP.

But I question whether you need the codebase feature at all. You just have to ensure that the relevant jar file is on the CLASSPATH of both the Registry and the clients. The simplest way to ensure that for the Registry is to use LocateRegistry.createRegistry() in the server JVM instead of the external rmiregistry program.

I'm also wondering why you're using JSON at all. RMI is built over Object Serialization. You don't need to add another serializer.

Korns answered 10/12, 2015 at 21:18 Comment(5)
Thanks for the feedback. Registry.bind() is being called as a result of my code calling UnicastRemoteObject.exportObject(). My registry and server are running on the same machine, clients are distributed across a network. Are you saying I don't need to run rmiregistry externally if I call LocateRegistry.createRegistry() before calling UnicastRemoteObject.exportObject()? I'll give it a try. Also, I'm using JSON to communicate with a network of Node.js servers.Adeline
UnicastRemoteObject.exportObject() (a) does not call Registry.bind(), and (b) does not appear in the stack trace. Ergo 'during UnicastRemoteObject.exportObject()' is not correct.Korns
I pruned the stack trace at the line referencing my function call, which was a line in my code calling UnicastRemoteObject.exportObject(), fyi :)Adeline
No. It came from your line of code that calls Registry.bind(). See the stack trace.Korns
The next line of the stack trace (which I did not show) was: at mai.mabs.Mabs.<init>(Mabs.java:390) where line 390 in Mabs.java is rmi_stub = (MabsRemote) UnicastRemoteObject.exportObject(r, rmi_port); hence my attributing the source of the exception to UnicastRemoteObject.exportObject(). In any case, I thank you sincerely for helping.Adeline

© 2022 - 2024 — McMap. All rights reserved.