开发者

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

开发者 https://www.devze.com 2023-04-08 16:22 出处:网络
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

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 开发者_Go百科one not executed yet. And another program (preferably java) can get or show the updated information on that variable from that application.


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.)
  • 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. RMI seems good choice for this.

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.
  2. RMI client which will access the server for latest update information.

There are many good tutorial including the Wiki link above. Check this out.


  1. propriatary protocol (via socket)
  2. embed HTTP server into your application and implement web service based communication.
  3. use JMX
  4. Use JDI (Java Debugger Interface).

$1 and $2 require some modification of controlled application. $3 and $4 do not require any modification of your applcation.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号