简体   繁体   English

如何使用Java在计算机上当前正在运行的另一个Java应用程序上查找和执行方法?

[英]How to find and execute a method on another java application currently running on computer using java?

For example, lets say I have hello.java (arbitrarily), if it was running and user changed some accessible (not private) variable in that application by providing input while running, this application would have the variable different compared to one not executed yet. 例如,假设我有hello.java(任意),如果它正在运行并且用户通过在运行时提供输入来更改了该应用程序中的一些可访问(非私有)变量,则该应用程序的变量将与尚未执行的变量不同。 And another program (preferably java) can get or show the updated information on that variable from that application. 另一个程序(最好是java)可以从该应用程序获取或显示有关该变量的更新信息。

A variable holds a piece of information in memory. 变量在内存中保存一条信息。 If you want to make it accessible from another program, you have two choices : 如果要使其可从另一个程序访问,则有两种选择:

  • make it available using some communication protocol (plain socket, RMI, etc.) 使用某些通信协议(普通套接字,RMI等)使其可用
  • store it in a persistent store (the file system, a database), and have the second program read the persistent value from this persistent store. 将其存储在持久性存储(文件系统,数据库)中,然后让第二个程序从该持久性存储中读取持久性值。

Yours is the problem of accessing an object in a JVM remotely. 您的问题是远程访问JVM中的对象。 RMI seems good choice for this. RMI似乎是个不错的选择。

Here there will be two parts to your application 在这里,您的应用程序将分为两部分

  1. RMI server which will be the your application where the variable chance is supposed to happen. RMI服务器将是您应该发生可变机会的应用程序。
  2. RMI client which will access the server for latest update information. RMI客户端将访问服务器以获取最新更新信息。

There are many good tutorial including the Wiki link above. 有很多很好的教程,包括上面的Wiki链接。 Check this out. 检查这个出来。

  1. propriatary protocol (via socket) 专有协议(通过套接字)
  2. embed HTTP server into your application and implement web service based communication. 将HTTP服务器嵌入到您的应用程序中,并实现基于Web服务的通信。
  3. use JMX 使用JMX
  4. Use JDI (Java Debugger Interface). 使用JDI(Java调试器接口)。

$1 and $2 require some modification of controlled application. $ 1和$ 2需要对受控应用程序进行一些修改。 $3 and $4 do not require any modification of your applcation. $ 3和$ 4不需要修改您的申请。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM