Java RMI NoClassDefFoundError for javax.json.JsonValue in remote object

An exception is thrown during a call to UnicastRemoteObject.exportObject().

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

This part of the application worked fine until I added a method that returned 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 to run rmiregistry with a codebase, pointing directly to javax.json.jar, but the exception remains

 rmiregistry -J-Djava.rmi.server.codebase=file:///JarLibrary/javax.json.jar & 
+5
source share
1 answer

An exception is thrown during a call to UnicastRemoteObject.exportObject().

No no. See stack trace. This happens in Registry.bind().

You need to start the server with the set of properties java.rmi.server.codebase , but the file: // the code base URL will not work unless all the clients are running on the server host, in which case you do not really need the code function database in general, or it points to a shared folder in a form that can be used by both the registry and clients. This is usually HTTP.

But I doubt if you need the codebase function at all. You just need to make sure that the corresponding jar file is in the CLASSPATH of both the registry and the clients. The easiest way to verify that the registry uses LocateRegistry.createRegistry() in the server JVM instead of the external rmiregistry program.

I am also wondering why you use JSON at all. RMI is built on serializing objects. You do not need to add another serializer.

+3
source

Source: https://habr.com/ru/post/1237618/


All Articles