File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
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 Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Distributed Java
Bookmark "RMI: Compiling Client Class" Watch "RMI: Compiling Client Class" New topic
Author

RMI: Compiling Client Class

Ankit Varshney
Greenhorn

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...

Thanks


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

Joined: Feb 25, 2007
Posts: 1638

Ankit:
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
Greenhorn

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 -Djava.security.policy=server.policy engine.ComputeEngine
ComputeEngine exception:
java.security.AccessControlException: access denied (java.net.SocketPermission 1
27.0.0.1:1099 connect,resolve)
at java.security.AccessControlContext.checkPermission(Unknown Source)
at java.security.AccessController.checkPermission(Unknown Source)
at java.lang.SecurityManager.checkPermission(Unknown Source)
at java.lang.SecurityManager.checkConnect(Unknown Source)
at java.net.Socket.connect(Unknown Source)
at java.net.Socket.connect(Unknown Source)
at java.net.Socket.<init>(Unknown Source)
at java.net.Socket.<init>(Unknown Source)
at sun.rmi.transport.proxy.RMIDirectSocketFactory.createSocket(Unknown S
ource)
at sun.rmi.transport.proxy.RMIMasterSocketFactory.createSocket(Unknown S
ource)
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(ComputeEngine.java:35)

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(){
super();
}

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

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

if(System.getSecurityManager()==null){
System.setSecurityManager(new SecurityManager());

}

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



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

}


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

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.

Example:
c:\rmic example.hello.Server
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: RMI: Compiling Client Class