File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Distributed Java and the fly likes RMI: Compiling Client Class Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Head First Android this week in the Android forum!
JavaRanch » Java Forums » Java » Distributed Java
Bookmark "RMI: Compiling Client Class" Watch "RMI: Compiling Client Class" New topic

RMI: Compiling Client Class

Ankit Varshney

Joined: Aug 01, 2008
Posts: 29
Hello Friends,

When I am Compiling client class in RMI, its not compiling AS it required the Remote Interface to collect the reference which it got from look up.And i dont want to manually copy that Remote Interface from server to client.

Can anyone tell me the way by which client automatically got that interface and other needed claases from server.

I know one way using CODEBASE but i tink it is used at runtime...
Please Help me...


Have a nice time... <br />Ankit Kumar Varshney
Nitesh Kant

Joined: Feb 25, 2007
Posts: 1638

I know one way using CODEBASE but i tink it is used at runtime...

Yeah, "codebase" property is used for dynamic classloading at runtime.
It is used to download stubs and any class definitions related to remote method invocations.
You may write a wrapper over the JAVAC ant task to fetch some classes from server before compilation but generally that is not the way it happens.
If someone is publishing a remote object for general consumption, he/she also publishes the RemoteInterface which the clients can use.
It does not look like a good model where in a client at compile time has to download Interface definitions from the server.

apigee, a better way to API!
Ankit Varshney

Joined: Aug 01, 2008
Posts: 29
Thanks friend,

You are right that If someone is publishing a remote object for general consumption, he/she also publishes the RemoteInterface which the clients can use. But how client will get that Remote Interface,ultimately server has to give it manually to the client.....

I am also not able to use this codebse dynamically.

and one more problem i am getting...
I am not able to run my server using codebase and that policy file its throwing some exception...
The description is like this...

C:\Documents and Settings\NEWUSER\Desktop\java prgs\RMI_TEST>java -cp .;./comput
e.jar engine.ComputeEngine
ComputeEngine exception: access denied ( 1 connect,resolve)
at Source)
at Source)
at java.lang.SecurityManager.checkPermission(Unknown Source)
at java.lang.SecurityManager.checkConnect(Unknown Source)
at Source)
at Source)
at<init>(Unknown Source)
at<init>(Unknown Source)
at sun.rmi.transport.proxy.RMIDirectSocketFactory.createSocket(Unknown S
at sun.rmi.transport.proxy.RMIMasterSocketFactory.createSocket(Unknown S
at sun.rmi.transport.tcp.TCPEndpoint.newSocket(Unknown Source)
at sun.rmi.transport.tcp.TCPChannel.createConnection(Unknown Source)
at sun.rmi.transport.tcp.TCPChannel.newConnection(Unknown Source)
at sun.rmi.server.UnicastRef.newCall(Unknown Source)
at sun.rmi.registry.RegistryImpl_Stub.rebind(Unknown Source)
at engine.ComputeEngine.main(

and my server class is like this

package engine;

import java.rmi.RemoteException;
import java.rmi.registry.LocateRegistry;
import java.rmi.registry.Registry;
import java.rmi.server.UnicastRemoteObject;
import compute.Compute;
import compute.Task;

public class ComputeEngine implements Compute{

public ComputeEngine(){

public <T> T executeTask(Task<T> t){
return t.execute();

public static void main(String arg[]){
String codebase = "";;
System.setProperty( "java.rmi.server.codebase", codebase );
//System.setProperty( "", codebase+"server.policy" );

System.setSecurityManager(new SecurityManager());


String name="Compute";
Compute engine=new ComputeEngine();
Compute stub=(Compute)UnicastRemoteObject.exportObject(engine,0);
Registry registry=LocateRegistry.getRegistry();
System.out.println("ComputeEngine bound");

}catch(Exception e){
System.err.println("ComputeEngine exception:");


Please help me in this regard also...
Navaneetha krishnan

Joined: Sep 21, 2004
Posts: 26
There is no need to copy the remote interface to the client side. You have to use 'rmic' to generate client stubs and remote skeletons. Only after generating the stubs you should start coding the client part.

c:\rmic example.hello.Server
I agree. Here's the link:
subject: RMI: Compiling Client Class
jQuery in Action, 3rd edition