求救,RMI中绑定出错,急急急,,巨分狂送,不够再加!!!!!!!!!!

凌波微搏 2002-09-26 09:29:48
如能留下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.<init>(Socket.java:290)
at java.net.Socket.<init>(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.<init>(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
...全文
71 点赞 收藏 9
写回复
9 条回复
切换为时间正序
当前发帖距今超过3年,不再开放新的回复
发表回复
Kick_hotdog 2002-09-26
to webwing(中国鹰派):
如何在程序段里指定policy??
比如,policy跟随在我的应用程序所在目录中,
我如何将policy指定到我程序中?
================================================================

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.exe [自解压]

回复
webwing 2002-09-26
权限问题,运行时加上-Djava.security.policy=allPolicy就好了。
allPolicy文件内容如上。
回复
ezyw 2002-09-26
用这个bat文件
cd classes
set OLDCLASSPATH=%CLASSPATH%
set CLASSPATH=
start rmiregistry
java -Djava.rmi.server.codebase=http://localhost/ -Djava.security.policy=allPolicy 你的类文件
set CLASSPATH=%OLDCLASSPATH%
set OLDCLASSPATH=


其中设置allPolicy文件内容为grant
{
permission java.security.AllPermission;
};
回复
Kick_hotdog 2002-09-26
//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." );
}
}
在jdk\jre\security\java.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.
回复
wjmmml 2002-09-26
给出的错误是访问安全异常,侃侃你是否有权限。
回复
pentax 2002-09-26
是权限问题,如果你不修改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

回复
wjmmml 2002-09-26
给出的错误是访问安全异常,侃侃你是否有权限。
回复
凌波微搏 2002-09-26
再顶!!
回复
凌波微搏 2002-09-26
顶一下!!!!!!!!!
回复
相关推荐
发帖
Java SE
创建于2007-09-28

6.2w+

社区成员

Java 2 Standard Edition
申请成为版主
帖子事件
创建了帖子
2002-09-26 09:29
社区公告
暂无公告