Kompilacja RMI w konsoli - błedy

0

Siema, mam takie pliki:

import java.rmi.Remote; 
import java.rmi.RemoteException; 

public interface Hello extends Remote { 
    String sayHello(String name) throws RemoteException; 
}

import java.rmi.RemoteException;
import java.rmi.server.UnicastRemoteObject;
import java.util.*;

public class HelloImpl extends UnicastRemoteObject
    implements Hello {

    public HelloImpl() throws RemoteException {
        super();
    }

    public String sayHello(String name) throws RemoteException {
        System.out.println("I say hello !");
        return  "Hello "+name+" "+(new Date().toString());
    }

}
import java.rmi.Naming; 
import java.rmi.RemoteException; 

public class HelloCli { 

    public static void main(String[] args) { 

        String message = "blank"; 
        Hello obj = null; 

	try { 
	    obj = (Hello)Naming.lookup("//" + 
			 "127.0.0.1:6999" + "/HelloServer"); 
	    message = obj.sayHello("Przemek"); 
	    System.out.println(message);
	    
	} catch (Exception e) { 
	    System.out.println("HelloApplet exception: " + 
				    e.getMessage()); 
	    e.printStackTrace(); 
	} 
    } 

}
import java.rmi.Naming;
import java.rmi.RemoteException;
import java.rmi.RMISecurityManager;
import java.rmi.server.UnicastRemoteObject;
import java.rmi.registry.*;
import java.util.*;

public class HelloServer {


    public static void main(String args[]) { 

        // Create and install a security manager 
        if (System.getSecurityManager() == null) { 
	    System.setSecurityManager(new RMISecurityManager()); 
        } 
        try { 
//	    Registry reg=LocateRegistry.createRegistry(6999);
            Registry reg=LocateRegistry.getRegistry(6999);

	    HelloImpl obj = new HelloImpl(); 
	    // Bind this object instance to the name "HelloServer" 
	    Naming.rebind("//localhost:6999/HelloServer", obj); 
	    System.out.println("HelloServer bound in registry"); 
        } catch (Exception e) { 
	    System.out.println("HelloImpl err: " + e.getMessage()); 
	    e.printStackTrace(); 
        } 
    } 
}

Wszystkie powyższe pliki mam w katalogu C:\java. Plik polityki:

grant {
	// Allow everything for now
	permission java.security.AllPermission;
};

I mam problem przy kompilacji/uruchomieniu tego!

A robię to tak:

  1. javac *.java
  2. rmic HelloImpl
  3. start rmiregistry
  4. java -Djava.security.policy=plik.polityki HelloServer
  5. java -Djava.security.policy=plik.polityki HelloCli (albo java HelloCli - nieważne, bo też są błędy -.-)

Przewertowałem już dziesiątki stron, a dalej nic mi się nie kompiluje :( A oto treść błędu:

C:\Temp>javac *.java

C:\java>rmic HelloImpl

C:\java>start rmiregistry

C:\java>java -Djava.security.policy=policy HelloServer
HelloImpl err: Connection refused to host: localhost; nested exception is:
        java.net.ConnectException: Connection refused: connect
java.rmi.ConnectException: Connection refused to host: localhost; nested excepti
on is:
        java.net.ConnectException: Connection refused: connect
        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 java.rmi.Naming.rebind(Unknown Source)
        at HelloServer.main(HelloServer.java:23)
Caused by: java.net.ConnectException: Connection refused: connect
        at java.net.PlainSocketImpl.socketConnect(Native Method)
        at java.net.PlainSocketImpl.doConnect(Unknown Source)
        at java.net.PlainSocketImpl.connectToAddress(Unknown Source)
        at java.net.PlainSocketImpl.connect(Unknown Source)
        at java.net.SocksSocketImpl.connect(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)
        ... 7 more

POMOCY !

0

a wlasciwie to tresc bledu: ( wyżej mam C:\Temp, a to nieprawda, bo wszystko mam w C:\java, coś źle skopiowałem)

C:\java>javac *.java
 
C:\java>rmic HelloImpl
 
C:\java>start rmiregistry
 
C:\java>java -Djava.security.policy=policy HelloServer
HelloImpl err: Connection refused to host: localhost; nested exception is:
        java.net.ConnectException: Connection refused: connect
java.rmi.ConnectException: Connection refused to host: localhost; nested excepti
on is:
        java.net.ConnectException: Connection refused: connect
        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 java.rmi.Naming.rebind(Unknown Source)
        at HelloServer.main(HelloServer.java:23)
Caused by: java.net.ConnectException: Connection refused: connect
        at java.net.PlainSocketImpl.socketConnect(Native Method)
        at java.net.PlainSocketImpl.doConnect(Unknown Source)
        at java.net.PlainSocketImpl.connectToAddress(Unknown Source)
        at java.net.PlainSocketImpl.connect(Unknown Source)
        at java.net.SocksSocketImpl.connect(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)
        ... 7 more
0

Jeżeli używasz niestandardowego portu to trochę inaczej w serwerze:

Registry reg=LocateRegistry.createRegistry(6999);
HelloImpl obj = new HelloImpl();
Naming.rebind("rmi://localhost:6999/HelloServer", obj);
System.out.println("HelloServer bound in registry");

podobnie w kliencie: rmi://localhost:6999/HelloServer

0

dziala! Ogromnie dziekuje, uratowales mnie ! :)

1 użytkowników online, w tym zalogowanych: 0, gości: 1