积少成多

垃圾堆

  BlogJava :: 首页 :: 联系 :: 聚合  :: 管理
  29 Posts :: 1 Stories :: 5 Comments :: 0 Trackbacks
package hello;
public interface Hello extends java.rmi.Remote{
    String sayHello() throws java.rmi.RemoteException;
}

package hello;
import java.rmi.
*;
public class HelloClient {
    
public static void main(String args[]){
        System.setSecurityManager(new RMISecurityManager());
        try{
            Hello obj 
= (Hello)Naming.lookup("HelloServer");
            String message
=obj.sayHello();
            System.out.println(message);
        }catch(Exception e){
            e.printStackTrace();
        }
    }
}

package hello;
import java.rmi.
*;
import java.rmi.registry.LocateRegistry;
import java.rmi.server.UnicastRemoteObject;
public class HelloImpl extends UnicastRemoteObject implements Hello{
    private String name;
    
public HelloImpl(String s) throws java.rmi.RemoteException{
        super();
        name
=s;
    }
    
public String sayHello()throws RemoteException{
        
return "hello world";
    }
    
public static void main(String args[]){
        System.setSecurityManager(new RMISecurityManager());
        try{
            HelloImpl obj 
= new HelloImpl("HelloServer");
            LocateRegistry.createRegistry(
1099); 
            Naming.rebind("HelloServer", obj);
            System.out.println("HelloImpl created 
and bound in the registry to the name HelloServer");
        }catch(Exception e){
            e.printStackTrace();
        }
    }
}

安全策略文件
grant {
    permission java.security.AllPermission;
    };

运行脚本:
Set CLASSPATH=%CLASSPATH%;c:\         没有空格
javac -d .. *.java                                  在hello目录下
rmic -d . hello.HelloImpl                           在hello的父目录下
java -Djava.security.policy=file:C:/java.policy hello.HelloImpl        注意安全策略文件
java -Djava.security.policy=file:/C:/java.policy hello.HelloClient     注意安全策略文件

相关资料:
http://blog.csdn.net/coolriver/archive/2004/09/10/100702.aspx
http://topic.csdn.net/t/20020310/12/566253.html
http://topic.csdn.net/u/20070426/08/b852e323-08c6-4f80-b87a-937e24af237d.html

posted on 2011-06-13 15:18 思无 阅读(256) 评论(0)  编辑  收藏 所属分类: Java

只有注册用户登录后才能发表评论。


网站导航: