当前位置: 技术问答>java相关
求救,RMI中绑定出错,急急急,,巨分狂送,不够再加!!!!!!!!!!
来源: 互联网 发布时间:2015-09-15
本文导语: 如能留下Email,或者QQ,就更好。 在运行一个Rmi服务端程序的时候提示绑定出错,下面是打印出来的出错信息,这个程序是一个例程。 java.security.AccessControlException: access denied (java.net.SocketPermission 1 27.0.0.1:10009 connect...
如能留下Email,或者QQ,就更好。
在运行一个Rmi服务端程序的时候提示绑定出错,下面是打印出来的出错信息,这个程序是一个例程。
java.security.AccessControlException: access denied (java.net.SocketPermission 1
27.0.0.1:10009 connect,resolve)
at java.security.AccessControlContext.checkPermission(AccessControlConte
xt.java:270)
at java.security.AccessController.checkPermission(AccessController.java:
401)
at java.lang.SecurityManager.checkPermission(SecurityManager.java:542)
at java.lang.SecurityManager.checkConnect(SecurityManager.java:1044)
at java.net.Socket.connect(Socket.java:419)
at java.net.Socket.connect(Socket.java:375)
at java.net.Socket.(Socket.java:290)
at java.net.Socket.(Socket.java:118)
at sun.rmi.transport.proxy.RMIDirectSocketFactory.createSocket(RMIDirect
SocketFactory.java:22)
at sun.rmi.transport.proxy.RMIMasterSocketFactory.createSocket(RMIMaster
SocketFactory.java:122)
at sun.rmi.transport.tcp.TCPEndpoint.newSocket(TCPEndpoint.java:562)
at sun.rmi.transport.tcp.TCPChannel.createConnection(TCPChannel.java:185
)
at sun.rmi.transport.tcp.TCPChannel.newConnection(TCPChannel.java:171)
at sun.rmi.server.UnicastRef.newCall(UnicastRef.java:313)
at sun.rmi.registry.RegistryImpl_Stub.rebind(Unknown Source)
at java.rmi.Naming.rebind(Naming.java:159)
at LocalRemoteServer.(LocalRemoteServer.java:81)
at LocalRemoteServer.main(LocalRemoteServer.java:38)
主程序:
/**
* Class: LocalRemoteServer
*
*/
import java.net.*;
import java.io.*;
import java.rmi.*;
import java.rmi.server.*;
import java.rmi.registry.LocateRegistry;
public class LocalRemoteServer
{
private static final int PORT = 10009;
//
// -> Change the name to your own computer name
//
private static final String HOST_NAME = "LocalHost";
// Instance of ourselves
private static LocalRemoteServer lrs;
public static void main
(
String[] args
)
{
// We need to set the security manager to the RMISecurityManager
System.setSecurityManager( new RMISecurityManager() );
try
{
lrs = new LocalRemoteServer();
}
catch ( java.rmi.UnknownHostException uhe )
{
System.out.println( "The host computer name you have specified, " + HOST_NAME + " does not match your real computer name." );
}
catch ( RemoteException re )
{
System.out.println( "Error starting service" );
System.out.println( "" + re );
}
catch ( MalformedURLException mURLe )
{
System.out.println( "Internal error" + mURLe );
}
catch ( NotBoundException nbe )
{
System.out.println( "Not Bound" );
System.out.println( "" + nbe );
}
} // main
// Constructor
public LocalRemoteServer()
throws RemoteException,
MalformedURLException,
NotBoundException
{
LocateRegistry.createRegistry( PORT );
System.out.println( "Registry created on host computer " + HOST_NAME + " on port " + Integer.toString( PORT) );
RemoteModelMgrImpl rmmImpl = new RemoteModelMgrImpl();
System.out.println( "RemoteModelImpl object created" );
String urlString = "//" + HOST_NAME + ":" + Integer.toString( PORT ) + "/" + "RemoteModelManager";
try
{
Naming.rebind( urlString, rmmImpl );
}
catch(Exception e)
{
System.out.println("bind error..............");
e.printStackTrace();
System.exit(0);
}
System.out.println( "Bindings Finished, waiting for client requests." );
}
} // class LocalRemoteServer
在运行一个Rmi服务端程序的时候提示绑定出错,下面是打印出来的出错信息,这个程序是一个例程。
java.security.AccessControlException: access denied (java.net.SocketPermission 1
27.0.0.1:10009 connect,resolve)
at java.security.AccessControlContext.checkPermission(AccessControlConte
xt.java:270)
at java.security.AccessController.checkPermission(AccessController.java:
401)
at java.lang.SecurityManager.checkPermission(SecurityManager.java:542)
at java.lang.SecurityManager.checkConnect(SecurityManager.java:1044)
at java.net.Socket.connect(Socket.java:419)
at java.net.Socket.connect(Socket.java:375)
at java.net.Socket.(Socket.java:290)
at java.net.Socket.(Socket.java:118)
at sun.rmi.transport.proxy.RMIDirectSocketFactory.createSocket(RMIDirect
SocketFactory.java:22)
at sun.rmi.transport.proxy.RMIMasterSocketFactory.createSocket(RMIMaster
SocketFactory.java:122)
at sun.rmi.transport.tcp.TCPEndpoint.newSocket(TCPEndpoint.java:562)
at sun.rmi.transport.tcp.TCPChannel.createConnection(TCPChannel.java:185
)
at sun.rmi.transport.tcp.TCPChannel.newConnection(TCPChannel.java:171)
at sun.rmi.server.UnicastRef.newCall(UnicastRef.java:313)
at sun.rmi.registry.RegistryImpl_Stub.rebind(Unknown Source)
at java.rmi.Naming.rebind(Naming.java:159)
at LocalRemoteServer.(LocalRemoteServer.java:81)
at LocalRemoteServer.main(LocalRemoteServer.java:38)
主程序:
/**
* Class: LocalRemoteServer
*
*/
import java.net.*;
import java.io.*;
import java.rmi.*;
import java.rmi.server.*;
import java.rmi.registry.LocateRegistry;
public class LocalRemoteServer
{
private static final int PORT = 10009;
//
// -> Change the name to your own computer name
//
private static final String HOST_NAME = "LocalHost";
// Instance of ourselves
private static LocalRemoteServer lrs;
public static void main
(
String[] args
)
{
// We need to set the security manager to the RMISecurityManager
System.setSecurityManager( new RMISecurityManager() );
try
{
lrs = new LocalRemoteServer();
}
catch ( java.rmi.UnknownHostException uhe )
{
System.out.println( "The host computer name you have specified, " + HOST_NAME + " does not match your real computer name." );
}
catch ( RemoteException re )
{
System.out.println( "Error starting service" );
System.out.println( "" + re );
}
catch ( MalformedURLException mURLe )
{
System.out.println( "Internal error" + mURLe );
}
catch ( NotBoundException nbe )
{
System.out.println( "Not Bound" );
System.out.println( "" + nbe );
}
} // main
// Constructor
public LocalRemoteServer()
throws RemoteException,
MalformedURLException,
NotBoundException
{
LocateRegistry.createRegistry( PORT );
System.out.println( "Registry created on host computer " + HOST_NAME + " on port " + Integer.toString( PORT) );
RemoteModelMgrImpl rmmImpl = new RemoteModelMgrImpl();
System.out.println( "RemoteModelImpl object created" );
String urlString = "//" + HOST_NAME + ":" + Integer.toString( PORT ) + "/" + "RemoteModelManager";
try
{
Naming.rebind( urlString, rmmImpl );
}
catch(Exception e)
{
System.out.println("bind error..............");
e.printStackTrace();
System.exit(0);
}
System.out.println( "Bindings Finished, waiting for client requests." );
}
} // class LocalRemoteServer
|
是权限问题,如果你不修改policy策略文件,不允许你打开Socket,找到jdk下的java.policy文件,在其中仿照其他格式将
// allows anyone to listen on un-privileged ports
permission java.net.SocketPermission "localhost:1024-", "listen";
改为:
permission java.net.SocketPermission "*:1024-65535", "listen,accept,connect";
就是允许1024以上的端口监听,接受,连接,如果是在JBuilder下调试,就要修改JBuilder下面的,也可以参照自己写一个,在运行时自己指定policy,命令格式如下:
java -Djava.rmi.server.codebase=http://myhost/~myusrname/myclasses/ -Djava.security.policy=$HOME/mysrc/policy ?examples.hello.HelloImpl
相关连接:
http://java.sun.com/products/jdk/1.2/docs/guide/security/PolicyFiles.html
http://java.sun.com/products/jdk/1.2/docs/guide/security/permissions.html
// allows anyone to listen on un-privileged ports
permission java.net.SocketPermission "localhost:1024-", "listen";
改为:
permission java.net.SocketPermission "*:1024-65535", "listen,accept,connect";
就是允许1024以上的端口监听,接受,连接,如果是在JBuilder下调试,就要修改JBuilder下面的,也可以参照自己写一个,在运行时自己指定policy,命令格式如下:
java -Djava.rmi.server.codebase=http://myhost/~myusrname/myclasses/ -Djava.security.policy=$HOME/mysrc/policy ?examples.hello.HelloImpl
相关连接:
http://java.sun.com/products/jdk/1.2/docs/guide/security/PolicyFiles.html
http://java.sun.com/products/jdk/1.2/docs/guide/security/permissions.html
|
//interface
import java.rmi.*;
import java.rmi.server.*;
public interface RemoteModelMgr extends java.rmi.Remote{
public void sayHello()throws RemoteException;
}
//
import java.rmi.server.*;
import java.rmi.*;
import java.io.Serializable;
public class RemoteModelMgrImpl implements RemoteModelMgr,Serializable{
public RemoteModelMgrImpl() {
}
public void sayHello()throws RemoteException{
System.out.println("Say Hello!");
}
}
//
import java.net.*;
import java.io.*;
import java.rmi.*;
import java.rmi.server.*;
import java.rmi.registry.LocateRegistry;
public class LocalRemoteServer
{
private static final int PORT = 10009;
//
// -> Change the name to your own computer name
//
private static final String HOST_NAME = "LocalHost";
// Instance of ourselves
private static LocalRemoteServer lrs;
public static void main(String[] args)
{
// We need to set the security manager to the RMISecurityManager
System.setSecurityManager( new RMISecurityManager() );
try
{
lrs = new LocalRemoteServer();
}
catch ( java.rmi.UnknownHostException uhe )
{
System.out.println( "The host computer name you have specified, " + HOST_NAME + " does not match your real computer name." );
}
catch ( RemoteException re )
{
System.out.println( "Error starting service" );
System.out.println( "" + re );
}
catch ( MalformedURLException mURLe )
{
System.out.println( "Internal error" + mURLe );
}
catch ( NotBoundException nbe )
{
System.out.println( "Not Bound" );
System.out.println( "" + nbe );
}
} // main
// Constructor
public LocalRemoteServer() throws RemoteException, MalformedURLException,NotBoundException
{
LocateRegistry.createRegistry( PORT );
System.out.println( "Registry created on host computer " + HOST_NAME + " on port " + Integer.toString( PORT) );
RemoteModelMgrImpl rmmImpl = new RemoteModelMgrImpl();
System.out.println( "RemoteModelImpl object created" );
String urlString = "//" + HOST_NAME + ":" + Integer.toString( PORT ) + "/" + "RemoteModelManager";
try
{
Naming.rebind( urlString, rmmImpl );
}
catch(Exception e)
{
System.out.println("bind error..............");
e.printStackTrace();
System.exit(0);
}
System.out.println( "Bindings Finished, waiting for client requests." );
}
}
在jdkjresecurityjava.policy中修改
permission java.net.SocketPermission "*:1024-65535", "listen,accept,connect";
运行结果:
Registry created on host computer LocalHost on port 10009
RemoteModelImpl object created
Bindings Finished, waiting for client requests.
================================================================
CSDN 论坛助手 Ver 1.0 B0402提供下载。 改进了很多,功能完备!
★ 浏览帖子速度极快![建议系统使用ie5.5以上]。 ★ 多种帖子实现界面。
★ 保存帖子到本地[html格式]★ 监视您关注帖子的回复更新。
★ 可以直接发贴、回复帖子★ 采用XML接口,可以一次性显示4页帖子,同时支持自定义每次显示帖子数量。可以浏览历史记录!
★ 支持在线检测程序升级情况,可及时获得程序更新的信息。
★★ 签名 ●
可以在您的每个帖子的后面自动加上一个自己设计的签名哟。
Http://www.ChinaOK.net/csdn/csdn.zip
Http://www.ChinaOK.net/csdn/csdn.rar
Http://www.ChinaOK.net/csdn/csdn.
import java.rmi.*;
import java.rmi.server.*;
public interface RemoteModelMgr extends java.rmi.Remote{
public void sayHello()throws RemoteException;
}
//
import java.rmi.server.*;
import java.rmi.*;
import java.io.Serializable;
public class RemoteModelMgrImpl implements RemoteModelMgr,Serializable{
public RemoteModelMgrImpl() {
}
public void sayHello()throws RemoteException{
System.out.println("Say Hello!");
}
}
//
import java.net.*;
import java.io.*;
import java.rmi.*;
import java.rmi.server.*;
import java.rmi.registry.LocateRegistry;
public class LocalRemoteServer
{
private static final int PORT = 10009;
//
// -> Change the name to your own computer name
//
private static final String HOST_NAME = "LocalHost";
// Instance of ourselves
private static LocalRemoteServer lrs;
public static void main(String[] args)
{
// We need to set the security manager to the RMISecurityManager
System.setSecurityManager( new RMISecurityManager() );
try
{
lrs = new LocalRemoteServer();
}
catch ( java.rmi.UnknownHostException uhe )
{
System.out.println( "The host computer name you have specified, " + HOST_NAME + " does not match your real computer name." );
}
catch ( RemoteException re )
{
System.out.println( "Error starting service" );
System.out.println( "" + re );
}
catch ( MalformedURLException mURLe )
{
System.out.println( "Internal error" + mURLe );
}
catch ( NotBoundException nbe )
{
System.out.println( "Not Bound" );
System.out.println( "" + nbe );
}
} // main
// Constructor
public LocalRemoteServer() throws RemoteException, MalformedURLException,NotBoundException
{
LocateRegistry.createRegistry( PORT );
System.out.println( "Registry created on host computer " + HOST_NAME + " on port " + Integer.toString( PORT) );
RemoteModelMgrImpl rmmImpl = new RemoteModelMgrImpl();
System.out.println( "RemoteModelImpl object created" );
String urlString = "//" + HOST_NAME + ":" + Integer.toString( PORT ) + "/" + "RemoteModelManager";
try
{
Naming.rebind( urlString, rmmImpl );
}
catch(Exception e)
{
System.out.println("bind error..............");
e.printStackTrace();
System.exit(0);
}
System.out.println( "Bindings Finished, waiting for client requests." );
}
}
在jdkjresecurityjava.policy中修改
permission java.net.SocketPermission "*:1024-65535", "listen,accept,connect";
运行结果:
Registry created on host computer LocalHost on port 10009
RemoteModelImpl object created
Bindings Finished, waiting for client requests.
================================================================
CSDN 论坛助手 Ver 1.0 B0402提供下载。 改进了很多,功能完备!
★ 浏览帖子速度极快![建议系统使用ie5.5以上]。 ★ 多种帖子实现界面。
★ 保存帖子到本地[html格式]★ 监视您关注帖子的回复更新。
★ 可以直接发贴、回复帖子★ 采用XML接口,可以一次性显示4页帖子,同时支持自定义每次显示帖子数量。可以浏览历史记录!
★ 支持在线检测程序升级情况,可及时获得程序更新的信息。
★★ 签名 ●
可以在您的每个帖子的后面自动加上一个自己设计的签名哟。
Http://www.ChinaOK.net/csdn/csdn.zip
Http://www.ChinaOK.net/csdn/csdn.rar
Http://www.ChinaOK.net/csdn/csdn.