标题:用RMI实现的小程序,执行不了,希望大家帮帮忙,谢谢
取消只看楼主
观星
Rank: 2
等 级:论坛游民
帖 子:77
专家分:45
注 册:2008-5-1
结帖率:90.91%
已结贴  问题点数:20 回复次数:2 
用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();
        }
    }
}
搜索更多相关主题的帖子: RMI 
2010-03-15 11:06
观星
Rank: 2
等 级:论坛游民
帖 子:77
专家分:45
注 册:2008-5-1
得分:0 
哈喽 路过的大侠,有编译执行成功的么?
2010-03-17 14:47
观星
Rank: 2
等 级:论坛游民
帖 子:77
专家分:45
注 册:2008-5-1
得分:0 
谢谢你啦~~
2010-03-18 13:09



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-299463-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.043607 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved