• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

RMI: Compiling Client Class

 
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Bartender
Posts: 1638
IntelliJ IDE MySQL Database Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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.
 
Ankit Varshney
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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...
 
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
reply
    Bookmark Topic Watch Topic
  • New Topic