下面是我的程序:
import java.rmi.server.UnicastRemoteObject;
import java.rmi.*;public class ArithImpl extends UnicastRemoteObject implements Arith{
private static final long serialVersionUID = 1124794857849355931L;
    private String objectname;public ArithImpl(String objectname)throws RemoteException
{
super();
this.objectname = objectname;
}
/**
 * a.length == b.length;
 */
public int[]add(int []a,int []b)
{
for(int i = 0 ;i<a.length;i++)
a[i]+=b[i]; 
return a;
}
public static void main(String[] args) {
    RMISecurityManager sm = new RMISecurityManager();
    System.setSecurityManager(sm);
    try{
     ArithImpl obj = new ArithImpl("ArithServer");
     Naming.rebind("ArithServer",obj);
     System.out.println("//hostname/ArithServer bound in registry!");
    }catch(Exception e )
    {
     System.out.println("ArithImpl error:"+e.getMessage());
     e.printStackTrace();
    }
}
}这是抛出的异常:
ArithImpl error:access denied (java.net.SocketPermission 127.0.0.1:1099 connect,resolve)
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.<init>(Unknown Source)
at java.net.Socket.<init>(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.rebind(Unknown Source)
at java.rmi.Naming.rebind(Unknown Source)
at ArithImpl.main(ArithImpl.java:28)
请问这个问题如何解决?

解决方案 »

  1.   

    应该是没有生成ArithImpl_Stub.clas 的文件运行 
    执行一下 ArithImpl 应该可以的
      

  2.   

    为什么我编译产生了class文件后用“rmic ArithImpl"编译的时候会提示”Class ArithImpl not found"?目录是对的
      

  3.   

    举个例子 假设 ArithImpl.java 在c:\ch7\Rmi 目录下
    就应该 c:\ch7\Rmi>rmic  ArithImpl
      

  4.   

    举个例子 假设 ArithImpl.java 在c:\ch7\Rmi 目录下
    就应该 c:\ch7\Rmi>rmic  ArithImpl如上操作了还是报class not found.高手指点
      

  5.   

    呵呵 问题解决
    需要将c:\ch7\Rmi加入classpath
      

  6.   

    或者设置classpath,或者在你编译的目录来执行