Problem: möchte ein einfaches Hello World mit Java 6 und RMI realisieren. Nutze Eclipse und habe folgenden Quellcodebaum
src/client/Client.java
src/server/Server.java
src/shared/Hello.java
src/shared/HelloImpl.java
Hello.java
HelloImpl.java
Server.java
Die rmiregistry läuft
aber trotzdem erhalte ich
Kann den Fehler nicht wirklich nachvollziehen. shared.Hello liegt im gleichen Classpath wie auch der Server.
Fragen:
1. Wie löse ich das Problem?
2. Früher hatte man noch rmic benutzt, der Stub wird also nun on-the-fly erzeugt und geladen, danach aber wieder zerstört, so dass ich keinen permanenten Stub habe?
src/client/Client.java
src/server/Server.java
src/shared/Hello.java
src/shared/HelloImpl.java
Hello.java
Java:
public interface Hello extends Remote, Serializable {
String sayHello() throws RemoteException;
}
HelloImpl.java
Java:
public class HelloImpl implements Hello {
public HelloImpl() throws RemoteException {}
public String sayHello() {
return "Hello, world!";
}
}
Server.java
Java:
public class Server {
public static void main(String args[]) throws RemoteException {
Registry registry = LocateRegistry.getRegistry(Registry.REGISTRY_PORT);
Hello stub = (Hello) UnicastRemoteObject.exportObject( new HelloImpl(), 0);
registry.rebind("helloImpl", stub);
while(true);
}
}
Die rmiregistry läuft
Code:
tcp6 0 0 :::1099 :::* LISTEN 1000 27869 2956/rmiregistry
aber trotzdem erhalte ich
Java:
Exception in thread "main" java.rmi.ServerException: RemoteException occurred in server thread; nested exception is:
java.rmi.UnmarshalException: error unmarshalling arguments; nested exception is:
java.lang.ClassNotFoundException: shared.Hello
at sun.rmi.server.UnicastServerRef.oldDispatch(UnicastServerRef.java:413)
at sun.rmi.server.UnicastServerRef.dispatch(UnicastServerRef.java:267)
at sun.rmi.transport.Transport$1.run(Transport.java:177)
at java.security.AccessController.doPrivileged(Native Method)
at sun.rmi.transport.Transport.serviceCall(Transport.java:173)
at sun.rmi.transport.tcp.TCPTransport.handleMessages(TCPTransport.java:553)
at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run0(TCPTransport.java:808)
at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run(TCPTransport.java:667)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1110)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:603)
at java.lang.Thread.run(Thread.java:679)
at sun.rmi.transport.StreamRemoteCall.exceptionReceivedFromServer(StreamRemoteCall.java:273)
at sun.rmi.transport.StreamRemoteCall.executeCall(StreamRemoteCall.java:251)
at sun.rmi.server.UnicastRef.invoke(UnicastRef.java:377)
at sun.rmi.registry.RegistryImpl_Stub.rebind(Unknown Source)
at server.Server.main(Server.java:35)
Caused by: java.rmi.UnmarshalException: error unmarshalling arguments; nested exception is:
java.lang.ClassNotFoundException: shared.Hello
at sun.rmi.registry.RegistryImpl_Skel.dispatch(Unknown Source)
at sun.rmi.server.UnicastServerRef.oldDispatch(UnicastServerRef.java:403)
at sun.rmi.server.UnicastServerRef.dispatch(UnicastServerRef.java:267)
at sun.rmi.transport.Transport$1.run(Transport.java:177)
at java.security.AccessController.doPrivileged(Native Method)
at sun.rmi.transport.Transport.serviceCall(Transport.java:173)
at sun.rmi.transport.tcp.TCPTransport.handleMessages(TCPTransport.java:553)
at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run0(TCPTransport.java:808)
at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run(TCPTransport.java:667)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1110)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:603)
at java.lang.Thread.run(Thread.java:679)
Caused by: java.lang.ClassNotFoundException: shared.Hello
at java.net.URLClassLoader$1.run(URLClassLoader.java:217)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:205)
at java.lang.ClassLoader.loadClass(ClassLoader.java:321)
at java.lang.ClassLoader.loadClass(ClassLoader.java:266)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:264)
at sun.rmi.server.LoaderHandler.loadProxyInterfaces(LoaderHandler.java:728)
at sun.rmi.server.LoaderHandler.loadProxyClass(LoaderHandler.java:672)
at sun.rmi.server.LoaderHandler.loadProxyClass(LoaderHandler.java:609)
at java.rmi.server.RMIClassLoader$2.loadProxyClass(RMIClassLoader.java:646)
at java.rmi.server.RMIClassLoader.loadProxyClass(RMIClassLoader.java:311)
at sun.rmi.server.MarshalInputStream.resolveProxyClass(MarshalInputStream.java:255)
at java.io.ObjectInputStream.readProxyDesc(ObjectInputStream.java:1548)
at java.io.ObjectInputStream.readClassDesc(ObjectInputStream.java:1510)
at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:1749)
at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1346)
at java.io.ObjectInputStream.readObject(ObjectInputStream.java:368)
... 12 more
Kann den Fehler nicht wirklich nachvollziehen. shared.Hello liegt im gleichen Classpath wie auch der Server.
Fragen:
1. Wie löse ich das Problem?
2. Früher hatte man noch rmic benutzt, der Stub wird also nun on-the-fly erzeugt und geladen, danach aber wieder zerstört, so dass ich keinen permanenten Stub habe?
Zuletzt bearbeitet: