用java编写RMI程序,调试时出现access denied (java.net.SocketPermission 127.0.0.1:1099 connect,resolve),看过全部贴子了,没有解决

indianwolf 2002-03-10 12:12:11
我已经把整个论坛的关于RMI的贴子看了一遍,按照里面的方法试了,都不行。
下面,我描述一下问题:
系统: win2000 jb6企业版

hello.java //interface file

package testrmi_v3;
import java.rmi.*;
public interface hello extends Remote{
public String sayhello() throws RemoteException;
}

helloimpl.java //implement file

package testrmi_v3;
import java.rmi.*;
import java.rmi.server.UnicastRemoteObject;
import java.security.SecurityPermission;
import java.net.*;
public class helloimpl extends UnicastRemoteObject implements hello{
public helloimpl() throws RemoteException
{
super();

}
public String sayhello() throws RemoteException
{
return "hello , how are you";
}
}

helloserver.java //server file

package testrmi_v3;
import java.net.*;
import java.rmi.*;
import java.lang.*;
import java.rmi.server.UnicastRemoteObject;

public class helloserver {
public static void main(String args[])
{

System.setSecurityManager(new RMISecurityManager());
try
{
helloimpl obj=new helloimpl();
Naming.rebind("rmi://127.0.0.1:1099/helloserver",obj);
}
catch(Exception e)
{
System.out.println(e.getMessage());
}


}
}

helloclient.java //client file

package testrmi_v3;
import java.rmi.*;
import java.rmi.server.*;
import java.net.*;
public class helloclient {
public static void main(String args[])
{
System.setSecurityManager(new RMISecurityManager());
try
{
helloimpl myhello=(helloimpl)Naming.lookup("//127.0.0.1/helloserver");
System.out.println(myhello.sayhello());
}
catch(Exception e)
{
System.out.println(e.toString());
}
}
}

hello.policy //policy file
grant{
//allow all permission
permission java.security.AllPermission;
};

完全是照着jb6的help做的
而且有运行参数-Djava.rmi.server.codebase=file:d:\jubuilder6\myprogram\testrmi_v3\classes\-Djava.security.policy=file:d:\jbuilder6\myprogram\testrmi_v3\hello.policy

出现的问题是:access denied (java.net.SocketPermission 127.0.0.1:1099 connect,resolve)

我觉得应该是权限设置的不对,但我又说不出那里不对,请指教
...全文
1229 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
zy422 2002-04-25
  • 打赏
  • 举报
回复
你可能没注意到 在 Help 里 -Djava.rmi 前没有空格,但实际应用要在前面加上空格,至于路径按实际情况而定,

还有 Help 里没在程序里注册服务

你可以在 Naming 上一行加上

LocateRegistry.createRegistry(1099);

还应该
import java.rim.*;
import java.rim.registry;

我加上这些后测试过,一切 OK
DarkXie 2002-04-12
  • 打赏
  • 举报
回复
我用的是JBUILDER5/WIN2000,也出现了同样的问题,报的是一样的错误。

连JBUILDER5的RMI EXAMPLE都无法调通!郁闷~~~~
jjy1111 2002-04-12
  • 打赏
  • 举报
回复
-Djava.rmi.server.codebase=file:E:/MyProgram/Java/Hello/classes/ -Djava.security.policy=file:E:/MyProgram/Java/Hello/src/hello/rmi.policy

要注意的是在
-Djava.rmi.server.codebase=file:E:/MyProgram/Java/Hello/classes/
中如果你写成
-Djava.rmi.server.codebase=file:E:/MyProgram/Java/Hello/classes/hello
哪就会出现你描述的错误
kemble 2002-04-11
  • 打赏
  • 举报
回复
看清楚了,应该是这样的:
-Djava.security.policy=file:/d:/jbuilder6/myprogram/testrmi_v3/hello.policy



zytang 2002-04-11
  • 打赏
  • 举报
回复
也发现同样问题
请 高手
王鹏云 2002-03-10
  • 打赏
  • 举报
回复
你把你的-Djava中的参数设置的路径\改成/,比如:file:d:/jubuilder6……
我的时这样的,没有问题
outer2000 2002-03-10
  • 打赏
  • 举报
回复
up
indianwolf 2002-03-10
  • 打赏
  • 举报
回复
也不行,我已经试过了,我怀疑是不是win2000的问题
那位大哥有环境的话,把代码贴下去帮我试一下,如果不加改动就能运行的话,麻烦你给我个信

另外,我运行jb6自带的/samples/RMI/RMISample例子就没问题
真是奇怪,各位就算没有什么解决办法,也欢迎提出猜想,都让我试试

23,407

社区成员

发帖
与我相关
我的任务
社区描述
Java 非技术区
社区管理员
  • 非技术区社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧