如何在其他网络中存在的远程 JVM 中运行 java 文件/项目?
我正在尝试开发一个项目,该项目涉及在不同网络上的三个 JVM 中运行/执行 java 文件。如果我在本地运行 Java 文件,则应同时在所有三个或两个 JVM 中运行。
例如:/usr/local/helloWorld.java
class HelloWorld {
public static void main(String args[]){
System.out.println("Hello World");
}
}
当我运行这个 /usr/local/$java helloWorld
这应该在 JVM1(本地),JVM2(远程)中打印 Hello World 。
有没有办法说远程机器 JVM2 类文件的路径位于 /usr/local/
从那里执行该文件?
或者
我也应该在远程计算机上运行 $java helloWorld
吗?
谢谢
I am trying to work on a project which involves running/executing the java file in three JVM on different Network. If i locally run the Java file should simultaneously should run in all three or two JVM.
For example :/usr/local/helloWorld.java
class HelloWorld {
public static void main(String args[]){
System.out.println("Hello World");
}
}
When i run this /usr/local/$java helloWorld
This should print Hello World in JVM1(locally), JVM2(which is Remote) .
Is there way to say remote machine JVM2 that path for class file is located at /usr/local/
execute the file from there ?.
or
Should i run $java helloWorld
in remote machine also ?
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
普通 Java 没有现成的机制来调用和同步多台机器上的多个 JVM。
我建议根据您需要执行的操作,研究支持 Java 或 Terracotta 开源版本的网格平台。
http://www.terracotta.org/web/display/orgsite/Home
Plain Java does not have the mechanism readily available to invoke and synchronize multiple JVM's on multiple machines.
I would suggest looking into a grid platform supporting Java or the Open Source version of Terracotta depending on what you need to do.
http://www.terracotta.org/web/display/orgsite/Home
从纯 Java 的角度来看(相对于 ssh 到机器进行远程 shell 实例化),您可能需要考虑 RMI 和 Aglet 模式,其中对象可以是网络/jvm 透明的并在任何配置的目标上执行。
From a pure Java perspective (vs. ssh'ing to the machine for remote shell instantiation), you may want to consider RMI and an Aglet pattern where an object can be network/jvm transparent and execute on any configured target.
您可以查看 JGroups。然后,您可以以一种直到足够的“组成员”加入后才开始处理的方式来实现您的应用程序,一旦所有组成员都加入,您就可以使用 JGroups 让他们进行通信...但是您仍然需要启动 JVM手动或通过脚本...
You may have a look at JGroups. Then you can implement your app in a way it won't start processing until enough 'group members' have joined and once all group members have joined you can use JGroups to let them communicate... But you will still have to start the JVMs manually or by a script...
要在多个 JVM 上运行命令,我想您需要实现某种客户端/服务器或 P2P 或多播逻辑来将命令发送到客户端。要查找“远程类定义”,客户端可以使用 URLClassLoader从引用 JAR 文件和目录的 URL 搜索路径加载类和资源。
(编辑:我没有这方面的经验,但也许看看 Jini 。不确定不过会满足您的需求。)
To run commands on several JVM, I guess you'll need to implement some kind of client/server or P2P or multicast logic to send commands to the clients. To find "remote classes definitions", the clients could use an URLClassLoader to load classes and resources from a search path of URLs referring to both JAR files and directories.
(EDIT: I have no experience with it but maybe have a look at Jini. Not sure it will suit your needs though.)