Skip to Main Content

Java APIs

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Can't start rmiregistry from application

843793Jul 28 2010 — edited Jul 30 2010
Hi!

This is my code, which works, when I start rmiregistry from command-line:
public class RemoteDBStarter extends RMIStarter {

  private final static int PORT = 2359;
  private final static String NAME = "DB";

  public RemoteDBStarter() {
    super(RemoteDBInterface.class);
  }

  public void serverOrClientContinue() {
    try {
      RemoteDBInterface db = new RemoteDB();
      RemoteDBInterface stub = (RemoteDBInterface)UnicastRemoteObject
          .exportObject(db, PORT);

      Registry registry = LocateRegistry.getRegistry();
      registry.rebind(NAME, stub);
    }
    catch(Exception e) {
      //TODO
      e.printStackTrace();
    }
  }

  public static void main(String[] args) {
    new RemoteDBStarter();
  }
}
But when I try to add createRegistry
LocateRegistry.createRegistry(PORT);
RemoteDBInterface db = new RemoteDB();
RemoteDBInterface stub = (RemoteDBInterface)UnicastRemoteObject
    .exportObject(db, PORT);
I get exception
java.rmi.ConnectException: Connection refused to host: 10.x.x.x; nested exception is: 
	java.net.ConnectException: Connection refused: connect
	at sun.rmi.transport.tcp.TCPEndpoint.newSocket(TCPEndpoint.java:574)
	at sun.rmi.transport.tcp.TCPChannel.createConnection(TCPChannel.java:185)
	at sun.rmi.transport.tcp.TCPChannel.newConnection(TCPChannel.java:171)
	at sun.rmi.server.UnicastRef.newCall(UnicastRef.java:306)
	at sun.rmi.registry.RegistryImpl_Stub.rebind(Unknown Source)
	at server.RemoteDBStarter.serverOrClientContinue(RemoteDBStarter.java:32)
	at common.RMIStarter.<init>(RMIStarter.java:15)
	at server.RemoteDBStarter.<init>(RemoteDBStarter.java:16)
	at server.RemoteDBStarter.main(RemoteDBStarter.java:41)
Caused by: java.net.ConnectException: Connection refused: connect
	at java.net.PlainSocketImpl.socketConnect(Native Method)
	at java.net.PlainSocketImpl.doConnect(PlainSocketImpl.java:333)
	at java.net.PlainSocketImpl.connectToAddress(PlainSocketImpl.java:195)
	at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:182)
	at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:366)
	at java.net.Socket.connect(Socket.java:520)
	at java.net.Socket.connect(Socket.java:470)
	at java.net.Socket.<init>(Socket.java:367)
	at java.net.Socket.<init>(Socket.java:180)
	at sun.rmi.transport.proxy.RMIDirectSocketFactory.createSocket(RMIDirectSocketFactory.java:22)
	at sun.rmi.transport.proxy.RMIMasterSocketFactory.createSocket(RMIMasterSocketFactory.java:128)
	at sun.rmi.transport.tcp.TCPEndpoint.newSocket(TCPEndpoint.java:569)
	... 8 more
I tried to set hostname
System.setProperty("java.rmi.server.hostname", "localhost");
but it gives me same exception, as if it didn't even look for this property. Any suggestions?
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Aug 27 2010
Added on Jul 28 2010
15 comments
689 views