java 如何在 NetBeans 中运行 RMI?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/2469704/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to run RMI in NetBeans?
提问by Samurai
We can run RMI in netbeans by following steps.
我们可以通过以下步骤在 netbeans 中运行 RMI。
Right click build.xml -> Run target -> Other targets -> startRMI
右键 build.xml -> 运行目标 -> 其他目标 -> startRMI
But what i need is to start RMI registry through Java code. Is it possible? Help me.
但我需要的是通过 Java 代码启动 RMI 注册表。是否可以?帮我。
回答by stacker
In your implementation Class:
在您的实现类中:
YourClass extends UnicastRemoteObject implements YourService {
...
System.setSecurityManager(new java.rmi.RMISecurityManager());
registry = LocateRegistry.createRegistry( 1099 );
Naming.rebind("rmiName", this);
}
回答by Karussell
You should at first start the 'rmi server' and then the client. For this take a look at this tutorialsection 'Implement the server'.
您应该首先启动“rmi 服务器”,然后是客户端。为此,请查看本教程部分“实现服务器”。
BTW: I would recommend to use hessian librarywhich works over http!! so your admins do not need to explicitely open some ports for your app!
顺便说一句:我建议使用通过 http 工作的hessian 库!!所以你的管理员不需要明确地为你的应用打开一些端口!

