As of javase api 8, rmic
is deprecated. So generating stubs
dynamically is preferred by way of exporting objects as:
UnicastRemoteObject
and calling the UnicastRemoteObject()
constructor.UnicastRemoteObject
and calling the UnicastRemoteObject(port)
constructor. So I first called the UnicastRemoteObject(port)
constructor but got compilation error: no suitable constructor found for UnicastRemoteObject(int)
Then I tried calling UnicastRemoteObject()
constructor and still got the same compilation error. What is possibly going wrong?
EDIT: My code:
import java.rmi.*;
import java.rmi.server.*;
public class MyServer extends UnicastRemoteObject implements MyRemote {
MyServer()throws RemoteException {
new UnicastRemoteObject(5000);
}
//Other methods...
}
Exact quoted error:
no suitable constructor found for UnicastRemoteObject(int) constructor java.rmi.server.UnicastRemoteObject.UnicastRemoteObject() is not applicable (actual and formal argument lists differ in length) constructor java.rmi.server.UnicastRemoteObject.UnicastRemoteObject(int,java.rmi.server.RMIClientSocketFactory,java.rmi.server.RMIServerSocketFactory) is not applicable (actual and formal argument lists differ in length)
My question is, when java.rmi.server.UnicastRemoteObject
is present in javase8 api then why is the compiler giving error?
- Subclassing UnicastRemoteObject and calling the UnicastRemoteObject() constructor.
Wrong. Doing that requires rmic
.
- Subclassing
UnicastRemoteObject
and calling theUnicastRemoteObject(port)
constructor.
Correct. You've left out several cases:
Subclassing UnicastRemoteObject
and calling the UnicastRemoteObject(int, RMIClientSocketFactory, RMIServerSocketFactory)
constructor (possibly it is the other way round).
Not subclassing UnicastRemoteObject
and calling the UnicastRemoteObject.exportObject(Remote, int)
method.
Not subclassing UnicastRemoteObject
and calling the UnicastRemoteObject.exportObject(Remote, int, RMIClientSocketFactory, RMIServerSocketFactory)
method (again it is possibly the other way round).
EDIT
MyServer()throws RemoteException {
new UnicastRemoteObject(5000);
}
This is not how you call a base class constructor. The correct form is:
MyServer() throws RemoteException {
super(5000);
}
This is rather basic.