0

If i'm creating the RMI registry from command line, the client has no problem in binding objects to the registry.

However, if i'm starting the RMI registry using ProcessBuilder, it's giving error.

This is my code for creating rmiregistry using ProcessBuilder

ProcessBuilder obj = new ProcessBuilder ("rmiregistry","2500");

Process obj_process = obj.start();

The error that i'm getting for using ProcessBuilder when I'm trying to bind to my own RMI registry

java.rmi.ServerException: RemoteException occurred in server thread; nested exception is: 
java.rmi.UnmarshalException: error unmarshalling arguments; nested exception is: 
java.lang.ClassNotFoundException: node_func

node_func is an interface

Any ideas?

xavier666
  • 87
  • 12

2 Answers2

1

I don't see why you are starting a separate process when you could use LocateRegistry.createRegistry(). If you did that, this problem would disappear as well.

user207421
  • 305,947
  • 44
  • 307
  • 483
0

The exception is occurring because the rmiregistry application doesn't know where to load classes from. When you attempt to bind an object in the RMI registry, the registry downloads the class definition for that object.

The correct way to handle the problem is to set the java.rmi.server.codebase property

(right click on your project->run as->run configuration->Arguments->VM arguments).

The property requires that a directory path be terminated with a forward slash, like so:

-Djava.rmi.server.codebase=file:${workspace_location}/folder/

You may also be having trouble if the ${workspace_location} variable is a relative path and the rmiregistry application was not started in the same directory so the relative path is not correct for it. If you either make the path absolute, or start the rmiregistry in the appropriate directory, the ClassNotFoundException should go away. See the tutorial on the java.rmi.server.codebase property for a little more detailed information.

Hope it helps.

Credits to this guy

Community
  • 1
  • 1
F. Mayoral
  • 175
  • 1
  • 10
  • 1
    file: codebases only work properly if all clients are running in the local host as well. There are other ways to make the Registry work that don't involve the codebases, for example specifying a CLASSPATH env var or classpath argument when running it. – user207421 Sep 11 '12 at 00:52
  • No, that's not what I meant at all. What I *said* was 'there are other ways to make the Registry work that *don't involve the codebase*'. Please don't attempt to translate on my behalf. – user207421 Sep 11 '12 at 07:33
  • Those methods have nothing to do with OP question, which was something like "i have this error, how can i solve it?", and not "how can i create a rmi registry?", otherwise my initial answer would be different. – F. Mayoral Sep 11 '12 at 11:38
  • The OP's question is how to fix his Registry problem. He can do it with the CLASSPATH environment variable, with -J-Dclasspath, with the codebase feature, or with Locate.Registry.createRegistry(). These are all valid solutions to the OP's problem, and none of them is excluded by anything in his question. The problem with your answer is that you presented only one of those methods as 'the correct way'; you didn't mention the issue with file: codebases that I raised; you subsequently conflated nearly all of them as codebase features when they aren't; and you misrepresented that as my comment. – user207421 Sep 11 '12 at 11:50
  • Codebase is actually for dynamic loading of remote resources, i don't know where you get that codebase is for local clients but it's not like that, you just said it, you can define the codebase feature in the class path, it's exactly what i said in response to your first comment, it is still a codebase, if you don't like it you can always add your own response ;), thanks for your comments! http://docs.oracle.com/javase/6/docs/technotes/guides/rmi/codebase.html – F. Mayoral Sep 11 '12 at 12:06
  • @fer13488 I think your solution is viable but it's a little too complicated for me. (I'm just a newbie) EJP method about createRegistry helped me out in the end – xavier666 Sep 11 '12 at 14:40
  • You continue to get everything I say back to front. The problem with *file:* codebases, your suggestion, is that they only *work* locally, because a file: URL won't have the same meaning to a remote client. HTTP codebases work everywhere. A codebase is defined in the system property java.rmi.server.codebase. You cannot 'define the codebase in the CLASSPATH'. You keep conflating 'codebase' and 'CLASSPATH' as though they were the same thing. They aren't. I suggest you read my book on RMI for further enlightenment. – user207421 Sep 11 '12 at 22:52