C'è su questo forum qualche programmatore Java?
C'è su questo forum qualche programmatore Java?
Ultima Online :« Gatsu Uth DarthGott, brave warrior of Legionary »
Daoc :« Barrin Barrin, ice wizard of Avengers »
WoW :« Gandalug, fiery paladin of Angeli e Demoni »
Diablo3 :« Urza, melee wizard wannabe »
io conosco le basi, lo fo in uni...
hdr.
bnet profile
*Originally Posted by Hador
Lux.
Dwightz.
Provo comunque a descrivervi il mio problema, magari ci capita più di me.
Sto sviluppando un'applicazione che utilizza la RMI(non entro nei dettagli che tanto non sono rilevanti). Quando nel server eseguo il bind dell'oggetto col comando
Naming.rebind("//"+InetAddress.getByName("mio_indirizz_IP")+"/DATE-SERVER", dateServer);
mi da il seguente errore
Remote Exception: java.rmi.ServerException: RemoteException occurred in server thread; nested exception is:
java.rmi.ServerException: RemoteException occurred in server thread; nested exception is:
java.rmi.UnmarshalException: error unmarshalling arguments; nested exception is:
java.rmi.UnmarshalException: error unmarshalling arguments; nested exception is:
java.lang.ClassNotFoundException: rmi.DateServerInterface
java.lang.ClassNotFoundException: rmi.DateServerInterface
at sun.rmi.server.UnicastServerRef.oldDispatch(Unknow n Source)
at sun.rmi.server.UnicastServerRef.dispatch(Unknown Source)
at sun.rmi.transport.Transport$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at sun.rmi.transport.Transport.serviceCall(Unknown Source)
at sun.rmi.transport.tcp.TCPTransport.handleMessages( Unknown Source)
at sun.rmi.transport.tcp.TCPTransport$ConnectionHandl er.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
at sun.rmi.transport.StreamRemoteCall.exceptionReceiv edFromServer(StreamRemoteCall.java:247)
at sun.rmi.transport.StreamRemoteCall.executeCall(Str eamRemoteCall.java:223)
at sun.rmi.server.UnicastRef.invoke(UnicastRef.java:3 43)
at sun.rmi.registry.RegistryImpl_Stub.rebind(Unknown Source)
at java.rmi.Naming.rebind(Naming.java:160)
at rmi.DateServer.main(DateServer.java:31)
Caused by: java.rmi.UnmarshalException: error unmarshalling arguments; nested exception is:
java.lang.ClassNotFoundException: rmi.DateServerInterface
at sun.rmi.registry.RegistryImpl_Skel.dispatch(Unknow n Source)
at sun.rmi.server.UnicastServerRef.oldDispatch(Unknow n Source)
at sun.rmi.server.UnicastServerRef.dispatch(Unknown Source)
at sun.rmi.transport.Transport$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at sun.rmi.transport.Transport.serviceCall(Unknown Source)
at sun.rmi.transport.tcp.TCPTransport.handleMessages( Unknown Source)
at sun.rmi.transport.tcp.TCPTransport$ConnectionHandl er.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
Caused by: java.lang.ClassNotFoundException: rmi.DateServerInterface
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClassInternal(Unknown Source)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Unknown Source)
at sun.rmi.server.LoaderHandler.loadProxyInterfaces(U nknown Source)
at sun.rmi.server.LoaderHandler.loadProxyClass(Unknow n Source)
at sun.rmi.server.LoaderHandler.loadProxyClass(Unknow n Source)
at java.rmi.server.RMIClassLoader$2.loadProxyClass(Un known Source)
at java.rmi.server.RMIClassLoader.loadProxyClass(Unkn own Source)
at sun.rmi.server.MarshalInputStream.resolveProxyClas s(Unknown Source)
at java.io.ObjectInputStream.readProxyDesc(Unknown Source)
at java.io.ObjectInputStream.readClassDesc(Unknown Source)
at java.io.ObjectInputStream.readOrdinaryObject(Unkno wn Source)
at java.io.ObjectInputStream.readObject0(Unknown Source)
at java.io.ObjectInputStream.readObject(Unknown Source)
... 9 more
Ho inserito in grassetto l'errore vero e proprio, il resto è il risultato del printStackTrace() che dovrebbe servire per il debugging.
Idee?![]()
Ultima Online :« Gatsu Uth DarthGott, brave warrior of Legionary »
Daoc :« Barrin Barrin, ice wizard of Avengers »
WoW :« Gandalug, fiery paladin of Angeli e Demoni »
Diablo3 :« Urza, melee wizard wannabe »
Intanto:
Fammi vedere il codice del server e del client java per le RMI. E soprattutto dimmi che deve fare.Marshalling:
The process of gathering data and transforming it into a standard format before it is transmitted over a network so that the data can transcend network boundaries. In order for an object to be moved around a network, it must be converted into a data stream that corresponds with the packet structure of the network transfer protocol. This conversion is known as data marshalling. Data pieces are collected in a message buffer before they are marshaled. When the data is transmitted, the receiving computer converts the marshaled data back into an object.
Data marshalling is required when passing the output parameters of a program written in one language as input to a program written in another language.
http://www.ccs.neu.edu/home/kenb/com3337/rmi_tut.html
Qui ci sono degli esempi.
Quale editor usi intanto ?
Allora, io lavoro sotto Windows ed uso Netbeans.
Client
Serverpackage rmi;
import java.rmi.RemoteException;
import java.rmi.Naming;
public class DateClient {
public static void main(String[] args) {
System.setSecurityManager(new SecurityManager());
try{
String url = "//localhost/DATE-SERVER";
DateServerInterface remoteObject = (DateServerInterface) Naming.lookup(url);
System.out.println("Date: " + remoteObject.getDate());
}catch(RemoteException re){
System.out.println(re);
}catch(java.net.MalformedURLException ex){
System.out.println("Malformed url: " + ex);
}catch(java.rmi.NotBoundException ne){
System.out.println(ne);
}
}
}
Premetto che il codice è corretto. L'applicazione recupera la data dal server e la stampa a schermo.package rmi;
import java.rmi.RMISecurityManager;
import java.rmi.RemoteException;
import java.rmi.Naming;
import java.rmi.server.UnicastRemoteObject;
import java.net.InetAddress;
import java.net.UnknownHostException;
public class DateServer{
public static void main(String[] args){
try{
System.setSecurityManager(new RMISecurityManager());
System.out.println("Security Manger settato");
DateServerImpl dateServer = new DateServerImpl();
System.out.println("Creata una nuova istanza di DateServerImpl");
Naming.rebind("//"+InetAddress.getByName("xxx.xxx.xxx.xxx")+"/DATE-SERVER", dateServer);
System.out.println("Date Server created......");
}catch(java.net.MalformedURLException me){
System.out.println("Malformed URL: " + me.toString());
me.printStackTrace();
}catch(RemoteException re){
System.out.println("Remote Exception: " + re.toString());
re.printStackTrace();
}catch(UnknownHostException e){
System.out.println(e);
}
}
}
Di esempi ne ho parecchi fra le mani, non ho fatto che leggere tutorial e documentazione; il problema è che non riesco a far girare i programmi.
Ultima Online :« Gatsu Uth DarthGott, brave warrior of Legionary »
Daoc :« Barrin Barrin, ice wizard of Avengers »
WoW :« Gandalug, fiery paladin of Angeli e Demoni »
Diablo3 :« Urza, melee wizard wannabe »
Ok, così su due piedi mi verrebbe da dire:
java.lang.ClassNotFoundException: rmi.DateServerInterface
non trova questa interfaccia, di conseguenza non riesce a fare il marshalling, di conseguenza ti lancia una eccezione. Sicuro di avere incluso tutto quello che va incluso ?
Le classi si trovano tutte nella stessa cartella ed appartengono allo stesso package.
Non so quindi cosa possa non aver incluso.
Ultima Online :« Gatsu Uth DarthGott, brave warrior of Legionary »
Daoc :« Barrin Barrin, ice wizard of Avengers »
WoW :« Gandalug, fiery paladin of Angeli e Demoni »
Diablo3 :« Urza, melee wizard wannabe »
Dammi anche le interfacce e gli oggetti che le implementano che ti sei fatto tu per l'esercizio.
Intanto che attendo... prova così:
cambia questa riga
DateServerImpl dateServer = new DateServerImpl();
con
DateServerInterface dateServer = new DateServerImpl();
Ho provato ad apportare il cambiamento, ma l'errore persiste. Comunque queste sono le interfacce.
package rmi;
import java.rmi.*;
import java.rmi.server.*;
import java.util.Date;
import java.rmi.server.UnicastRemoteObject;
public class DateServerImpl extends UnicastRemoteObject implements DateServerInterface{
public DateServerImpl() throws RemoteException{
super();
}
public String getDate() throws RemoteException{
return new Date().toString();
}
}Comunque da quello che ho trovato in rete potrebbe essere un problema del classpath del registry. Purtroppo non ho molta confidenza con la RMI, mi trovo molto meglio con socket.package rmi;
import java.rmi.Remote;
import java.rmi.RemoteException;
import java.util.Date;
public interface DateServerInterface extends Remote{
String getDate() throws RemoteException;
}
Ultima Online :« Gatsu Uth DarthGott, brave warrior of Legionary »
Daoc :« Barrin Barrin, ice wizard of Avengers »
WoW :« Gandalug, fiery paladin of Angeli e Demoni »
Diablo3 :« Urza, melee wizard wannabe »
Allora, dopo una mare di ricerche sono riuscito a risolvere il problema.
Praticamente non era settato a dovere il classpath del registry. Le soluzioni sono due:
1)lo setti
2)fai una copia del registry nella cartella di lavoro
Ho optato per la due dato che su winzozz non so come si settano le variabili d'ambiente; non ci sta il setenv.![]()
Ultima Online :« Gatsu Uth DarthGott, brave warrior of Legionary »
Daoc :« Barrin Barrin, ice wizard of Avengers »
WoW :« Gandalug, fiery paladin of Angeli e Demoni »
Diablo3 :« Urza, melee wizard wannabe »
sto errore me lo dava pure a me (simile almeno, non ho letto tutta la stacktrace)
3 cose:
1 fai partire il registry di RMI (sta dnetro la directory bin della jdk e si chiama rmi registry)?
2 dopo aver compilato le classi, compili in rmi la classe DataServerImpl con il comando "rmic" da prompt del dos? E subito dopo registri in java la classe col main ? (comando java NomeClasseServer sempre dal prompt del dos)
3 dopo aver fatto questo ti sei ricordato di copiare il conseguente STUB che viene creato nella directory del client?
io mi scordavo di copiare lo stub :P e l'errore era molto simile
in bocca al lupo
p.s. ricordati di impostare il classpath della jdk (gestione risorse, proprieta, avanzate, variabili d'ambiente) cosi puoi usare il comando rmic e il comando java dalla directory di lavoro
---------------------------------------------------------------------------------------------
Cicci
Darath
ecco hai risolto mentre scrivevo :P
meglio cosi'
cmq per settare il classpath ti ho scritto nel post subito sopra come si fa![]()
---------------------------------------------------------------------------------------------
Cicci
Darath