I can't make compilator finds the class I want Exactly this:
ctx.rebind("MyInterfaceImplementacja", ref);
. I Could you please correct me?
package Pakiet;
import java.rmi.Remote;
import java.rmi.RemoteException;
public interface MyInterface extends Remote {
public String echo(String napis) throws RemoteException;
public int dodaj(int wrt1, int wrt2) throws RemoteException;
}
package Pakiet;
import java.rmi.RemoteException;
import javax.rmi.PortableRemoteObject;
public class MyInterfaceImplementacja extends PortableRemoteObject implements MyInterface {
protected MyInterfaceImplementacja() throws RemoteException {
super();
}
@Override
public String echo(String napis) throws RemoteException {
return "echo" + napis;
}
@Override
public int dodaj(int wrt1, int wrt2) throws RemoteException {
return wrt1 + wrt2;
}
}
public class MyInterfaceSerwer {
public static void main(String[] args) {
try{
MyInterfaceImplementacja ref = new MyInterfaceImplementacja();
Context ctx = new InitialContext();
ctx.rebind("MyInterfaceImplementacja", ref);
}catch(Exception e){e.printStackTrace();}
}
}
Try this
Extend the Implementation class to UnicastRemoteObject instead of PortableRemoteObject.
use rmi in your rebind method like this
ctx.rebind("rmi:MyInterfaceImplementacja", ref);
Keep this below guidelines for future use
down vote
If you are trying to implement the RMI. Please follow these steps Try this.... On Server Side:
Create Interface which extends java.rmi.Remote interface // shared by client and server
Create Implementation class of the Interface, and also extend it to UnicastRemoteObject
Now create the Server class which has the rebind method.
On Client Side:
Create Interface which extends java.rmi.Remote interface // shared by client and server
Create the Client class which has the lookup method.
eg: On SERVER
Car.java // Interface
CarImpl.java // Implementation Class
CarServer.java // Server Class
On CLIENT
Car.java // Interface
CarClient.java // Client Class