• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to run RMI without policy and codebase?

 
HiBob Chu
Ranch Hand
Posts: 86
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I want to modify my code for more simple, I remember I have saw a post here before which
said RMI could run without policy and codebase.
I have tried it , but it doesn't work.
Who can explain it clearly?
Regards.
 
HiBob Chu
Ranch Hand
Posts: 86
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It didn't work just because I installed a new virson of JDK, and I have to modify it's java.policy again . now, it works.
It's seem like that I have to provide a policy file. Because you shouldn't assume tester has
the same policy file as yours.
I still want to do something: move the policy file
into jar file, how to do it?
regards.
 
John Smith
Ranch Hand
Posts: 2937
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you don't use security manager, you don't need policy file.
Eugene.
 
HiBob Chu
Ranch Hand
Posts: 86
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi Eugene:
I have tried as you said. It does work, but
I couldnt custom port number. Do I miss anything?
regards.
 
John Smith
Ranch Hand
Posts: 2937
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You should have something like this in your code:
LocateRegistry.createRegistry(port);
...
registry = LocateRegistry.getRegistry(port);
...
registry.rebind(SERVICE_NAME, remoteDataFactory);
...
Eugene.
 
Sri Addanki
Ranch Hand
Posts: 195
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
where in does this code chip into?
i mean in which class do we write this, is it in the connection factory class, just before we do the lookup and rebind?
thanks,
sri
 
John Smith
Ranch Hand
Posts: 2937
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

where in does this code chip into?

You do it before you do anything else, -- I have it in a class called StartServer.
Eugene.
 
HiBob Chu
Ranch Hand
Posts: 86
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Eugene:
Thank you for your replays.
And I use another way which can work too.
**********************************
LocateRegistry.createRegistry(portNum);
remoteDataFactory connect = new Server();
Naming.rebind("//:" + portNum + "/" + SERVER_NAME,connect);
**********************************
Does it active as the same as yours?
 
Sri Addanki
Ranch Hand
Posts: 195
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Eugene,
Thanks. i'm starting registry in my code, like this.
In my server class:
java.rmi.registry.Registry registry = java.rmi.registry.LocateRegistry.createRegistry(1099);
Naming.rebind ("rmi://localhost:1099/" + args[0], dataServer);
and in my client class:
java.rmi.registry.Registry registry = java.rmi.registry.LocateRegistry.getRegistry();
if(serverName.startsWith("rmi://localhost:1099/"))
myServer_ = (RemoteIData)Naming.lookup(serverName);
Is this ok?
thanks,
sri
 
Sri Addanki
Ranch Hand
Posts: 195
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is this fine?
 
Mark Spritzler
ranger
Sheriff
Posts: 17278
6
IntelliJ IDE Mac Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well it looks like your code in the client is assuming the server and client are running on the same machine.
Actually your client doesn't need to find the registry, so to speak.
The URL "rmi://host_name_or_ip" is what tells the client where to do the lookup.
Mark
 
Sri Addanki
Ranch Hand
Posts: 195
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Mark Spritzler:

Actually your client doesn't need to find the registry, so to speak.
Mark

Yes, Mark...thanks alot!
i commented that line and compiled, it works fine. Yes , as you said the URL is just enough. Now i'll remove this getregistry line of code from my client.
I wasn't sure why i was using that.
thanks again,
sri
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic