用RMI实现的小程序,执行不了,希望大家帮帮忙,谢谢
编译成功后 执行时候有这些东西 不知道为什么,请大家指教D:\myj>java -Djava.rmi.server.codebase=file:/c:\java\ -Djava.security.policy=jav
a.policy HelloImpl
HelloImpl err: access denied ( 127.0.0.1:1099 connect,r
esolve)
java.security.AccessControlException: access denied ( 1
27.0.0.1:1099 connect,resolve)
at java.security.AccessControlContext.checkPermission(AccessControlConte
xt.java:323)
at java.security.AccessController.checkPermission(AccessController.java:
546)
at java.lang.SecurityManager.checkPermission(SecurityManager.java:532)
//下面是原文件
//接口 Hello.java
import java.rmi.Remote;
import java.rmi.RemoteException;
public interface Hello extends Remote
{
String sayHello() throws RemoteException;
}
//这是服务器程序 HelloImpl.java
import java.rmi.Naming;
import java.rmi.RemoteException;
import java.rmi.RMISecurityManager;
import java.rmi.server.UnicastRemoteObject;
import *;
public class HelloImpl extends UnicastRemoteObject implements Hello
{
public HelloImpl() throws RemoteException
{
super();
}
public String sayHello() throws RemoteException
{
return "hello world";
}
public static void main(String args[])
{
if(System.getSecurityManager()==null)
{
System.setSecurityManager(new RMISecurityManager());
}
try
{
HelloImpl obj=new HelloImpl();
Naming.rebind("rmi://127.0.0.1:1009/HelloSever",obj);
System.out.println("HelloSever bound in registry");
}
catch(Exception e)
{
System.out.println("HelloImpl err: "+e.getMessage());
e.printStackTrace();
}
}
}
//这是服务器程序 HelloClient.java
import java.rmi.*;
import java.rmi.Naming;
import java.rmi.RemoteException;
public class HelloClient
{
public static void main(String args[])
{
String message = "blank";
Hello obj=null;
System.setSecurityManager(new RMISecurityManager());
try
{
obj=(Hello)Naming.lookup("rmi://127.0.0.1/HelloSever");
message = obj.sayHello();
System.out.println(message);
}
catch(Exception e)
{
System.out.println("HelloClient exception: "+e.getMessage());
e.printStackTrace();
}
}
}