Meaningless Drivel is fun!*
The moose likes Developer Certification (SCJD/OCMJD) and the fly likes How to run RMI without policy and codebase? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Developer Certification (SCJD/OCMJD)
Bookmark "How to run RMI without policy and codebase?" Watch "How to run RMI without policy and codebase?" New topic
Author

How to run RMI without policy and codebase?

HiBob Chu
Ranch Hand

Joined: Aug 12, 2002
Posts: 86
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

Joined: Aug 12, 2002
Posts: 86
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

Joined: Oct 08, 2001
Posts: 2937
If you don't use security manager, you don't need policy file.
Eugene.
HiBob Chu
Ranch Hand

Joined: Aug 12, 2002
Posts: 86
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

Joined: Oct 08, 2001
Posts: 2937
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

Joined: Apr 27, 2001
Posts: 195
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

Joined: Oct 08, 2001
Posts: 2937

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

Joined: Aug 12, 2002
Posts: 86
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

Joined: Apr 27, 2001
Posts: 195
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

Joined: Apr 27, 2001
Posts: 195
Is this fine?
Mark Spritzler
ranger
Sheriff

Joined: Feb 05, 2001
Posts: 17249
    
    6

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


Perfect World Programming, LLC - Two Laptop Bag - Tube Organizer
How to Ask Questions the Smart Way FAQ
Sri Addanki
Ranch Hand

Joined: Apr 27, 2001
Posts: 195
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
 
 
subject: How to run RMI without policy and codebase?
 
Similar Threads
Problem with policy file, Security Manager
Access Control Exception
RemoteData Stub Error...
problem running client.jar executable
how to stop rmiregistry ??