下面是我的程序:
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)
请问这个问题如何解决?
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)
请问这个问题如何解决?
解决方案 »
- 服务器集群和负载均衡
- java的一个问题
- 如何限定形参的取值范围?
- 怎样捕捉long sum = Long.Long.MAX_VALUE+1的溢出错误
- 处理CLOB字段遇到的问题,test.txt大于700多字节就不行,600多字节可以。好郁闷
- 今天编写了第一个helloworld程序,痛快,散分!!
- 高分相求,来者有分,谁知道有关Applet中包的下载问题?
- 内部类 如何得到定义它的类的实例句柄?
- 再JAVA中有没有将"123,456,789"中逗号去掉的方法
- 页面上点击button后使其禁止点击的javascript函数如何写?
- 高手帮忙,急!RMI问题:UnicastRemoteObject(int port)怎么用?
- java对象序列化的问题
执行一下 ArithImpl 应该可以的
就应该 c:\ch7\Rmi>rmic ArithImpl
就应该 c:\ch7\Rmi>rmic ArithImpl如上操作了还是报class not found.高手指点
需要将c:\ch7\Rmi加入classpath