As I am coding RMI system, I ran into problem with exception at client side
Exception in thread "main" java.rmi.UnmarshalException: error unmarshalling return; nested exception is:
java.lang.ClassNotFoundException: com.cs.entity.LectureCourse
at sun.rmi.server.UnicastRef.invoke(UnicastRef.java:178)
at java.rmi.server.RemoteObjectInvocationHandler.invokeRemoteMethod(RemoteObjectInvocationHandler.java:178)
at java.rmi.server.RemoteObjectInvocationHandler.invoke(RemoteObjectInvocationHandler.java:132)
at $Proxy1.getNamedClass(Unknown Source)
at com.cs.test.ClientCRUD.main(ClientCRUD.java:40)
as com.cs.entity.LectureCourse
is a class that should be downloaded by client at runtime using RMI codebase feature I have checked to make sure
When I ran client and server at same node it works but exception is displayed at client when separate physical machine holds server and client separately.
Does anyone saw this problem before? Please help...
@EJP
Following is the code I used to start RMI registry (inside tomcat 7 contextInitialized)
final String value = "http://192.168.1.11:8080/csl/";
System.out.println(value);
System.setProperty("java.rmi.server.codebase", value);
registry = LocateRegistry.createRegistry(8899)
and this is the code I used to lookup registry in Client
System.setSecurityManager(new RMISecurityManager());
final String HOST = "192.168.1.11";
final int port = 8899;
final Registry registry = LocateRegistry.getRegistry(HOST, port);
I think they work correctly but the error frustrates me a lot
I think I find where the problem is. as mentioned before, RMI registry was started at Tomcat 7 contextInitialized method which should be invoked at starting up of the web project. it turns out the same piece of code for RMI server works pretty well if it is in an independent main Application. according to my several tests in different RMI server configurations, I concluded that
So the question turns out to be why Tomcat 7 does not start RMI registry differently? I am still working on that
Tomcat 7 contextInitialized method does something different then ordinary java main program
Of course it does. But without knowing what specific expectations you have, it is impossible to comment further.
I am not sure but codebase seems work only if the URL(I am using webserver) indicates to a specific jar file rather then directory. (this could be my misunderstanding of the tutorial or something like that)
It works a lot better because there is only one download, and you don't have to sprinkle .class files all over your codebase server: just deploy one or more JAR files.
If you're expecting RMI to load a JAR file from a directory without being specifically told to do so, it won't. If you don't name a JAR file it will look for .class files.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.