上面哪个问题解决了,但有出现了下面这个问题:麻烦各位高手赐教
F:\EJB\examples\A\MessageQueueDGC\classes>java -Djava.secutiry.policy=../java.po
licy com.wiley.compBooks.roman.rmi.mqdgc.QueueClient localhost 1000
Attempting to contact rmi://localhost:1000/MessageQueue
Error in lookup() java.security.AccessControlException: access denied (java.net.
SocketPermission 127.0.0.1:1000 connect,resolve)
F:\EJB\examples\A\MessageQueueDGC\classes>java -Djava.secutiry.policy=../java.po
licy com.wiley.compBooks.roman.rmi.mqdgc.QueueClient localhost 1000
Attempting to contact rmi://localhost:1000/MessageQueue
Error in lookup() java.security.AccessControlException: access denied (java.net.
SocketPermission 127.0.0.1:1000 connect,resolve)
F:\EJB\examples\A\MessageQueueDGC\classes>java -Djava.security.policy=../java.p
olicy com.wiley.compBooks.roman.rmi.mqdgc.QueueClient localhost 1000
Attempting to contact rmi://localhost:1000/MessageQueue
Error in lookup() java.rmi.UnmarshalException: error unmarshalling return; neste
d exception is:
java.io.EOFException
import java.rmi.Remote;
import java.rmi.RemoteException;
import java.rmi.Naming;
public class QueueClient extends Thread implements Remote {
public static void main (String[] args) {
IMessageQueue queue = null;
if (args.length != 2) {
System.err.println("Usage: Queue <hostname of MessageQueue remote object> <port to connect to>");
System.exit(-1);
}
System.setSecurityManager(new java.rmi.RMISecurityManager());
try {
String targetMachine = "rmi://" + args[0] + ":" + args[1] + "/MessageQueue";
System.out.println("Attempting to contact " + targetMachine);
Remote remoteObject = Naming.lookup(targetMachine);
if (remoteObject instanceof IMessageQueue) {
queue = (IMessageQueue) remoteObject;
}
else {
throw new Exception("Bad object returned from remote machine");
}
}
catch (Exception e) {
System.err.println("Error in lookup() " + e.toString());
System.exit(-1);
}
try { IChannel channel = queue.createChannel("Log");
QueueClient sender1 = new QueueClient(queue, channel, true, "Sender #1", 333); }
catch (Exception e) {
System.err.println(e.toString());
}
} private IChannel channel;
private boolean sendMessages;
private IMessageQueue queue;
private String name;
private int delay;
public QueueClient(IMessageQueue queue, IChannel channel, boolean sendMessages, String name, int delay) {
this.channel = channel;
this.sendMessages = sendMessages;
this.queue = queue;
this.name = name;
this.delay = delay;
start();
}
public void run() {
try {
if (sendMessages) { for (int i=0; i < 10; i++) {
queue.putMessage(channel, name + ": " + i++);
sleep(delay);
}
}
else {
while (true) {
String msg = (String) queue.getMessage(channel, 5000);
if (msg != null) System.out.println(msg);
}
}
}
catch (Exception e) {
System.err.println(e);
}
}
}
应该是其中的 Remote remoteObject = Naming.lookup(targetMachine);
抛出了异常