当前页面: 开发资料首页 → J2EE 专题 → 不知道错在哪了,帮忙看看。
不知道错在哪了,帮忙看看。
摘要: 不知道错在哪了,帮忙看看。
源码是三个文件,环境winxp+j2se+j2ee
//: c15:rmi:PerfectTimeI.java
import java.rmi.*;
public interface PerfectTimeI extends Remote {
long getPerfectTime() throws RemoteException;
}
//: c15:rmi:PerfectTime.java
import java.rmi.*;
import java.rmi.server.*;
import java.rmi.registry.*;
import java.net.*;
public class PerfectTime extends UnicastRemoteObject implements PerfectTimeI {
public long getPerfectTime()
throws RemoteException {
return System.currentTimeMillis();
}
public PerfectTime() throws RemoteException { }
public static void main(String[] args) throws Exception {
System.setSecurityManager(new RMISecurityManager());
PerfectTime pt = new PerfectTime();
Naming.bind( "PerfectTime", pt);
System.out.println("Ready to do time");
}
}
//: c15:rmi:DisplayPerfectTime.java
import java.rmi.*;
import java.rmi.registry.*;
public class DisplayPerfectTime {
public static void main(String[] args) throws Exception {
System.setSecurityManager( new RMISecurityManager());
PerfectTimeI t = (PerfectTimeI)Naming.lookup( "PerfectTime");
for(int i = 0; i < 10; i++)
System.out.println("Perfect time = " + t.getPerfectTime());
}
}
d:/jsdk/java>rmic DisplayPerfectTime
d:/jsdk/java>start rmiregistry
d:/jsdk/java>java DisplayPerfectTime
Exception in thread "main" java.security.AccessControlException: access denied (
java.net.SocketPermission 127.0.0.1:1099 connect,resolve)
at java.security.AccessControlContext.checkPermission(Unknown Source)
at java.security.AccessController.checkPermission(Unknown Source)
at java.lang.SecurityManager.checkPermission(Unknown Source)
at java.lang.SecurityManager.checkConnect(Unknown Source)
at java.net.Socket.connect(Unknown Source)
at java.net.Socket.connect(Unknown Source)
at java.net.Socket.
(Unknown Source)
at java.net.Socket.(Unknown Source)
at sun.rmi.transport.proxy.RMIDirectSocketFactory.createSocket(Unknown Source)
at sun.rmi.transport.proxy.RMIMasterSocketFactory.createSocket(Unknown Source)
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.lookup(Unknown Source)
at java.rmi.Naming.lookup(Unknown Source)
at DisplayPerfectTime.main(DisplayPerfectTime.java:25)
到底怎么改才能正常编译啊?
关注 学习