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 开发者_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
- RMI server which will be the your application where the variable chance is supposed to happen.
- RMI client which will access the server for latest update information.
There are many good tutorial including the Wiki link above. Check this out.
- propriatary protocol (via socket)
- embed HTTP server into your application and implement web service based communication.
- use JMX
- 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.
精彩评论