问题
I am trying to write a small internal tool to use for debugging focus problems in Swing applications. Right now the debugger tool is built in to the app and enabled via a debug command-line argument.
What I'd love to do is have a separate, standalone Java application that can connect to another JVM and listen for certain events (in this case, PropertyChangeEvents on the KeyboardFocusManager).
Ideally, it should be able to do this without any changes to the application being debugged, so it can be used "on-demand" to debug focus issues in any Swing app. Sort of like how VisualVM can attach to any running VM.
Is this possible? What are some starting points? JMX? Some other IPC mechanism?
回答1:
Not sure if this covers it, but.. Assuming the application is started with these flags:
-Xdebug -Xrunjdwp:transport=dt_socket,address=8001,server=y,suspend=n
You can attach the debugger to the process remotely using Eclipse.
回答2:
You can use the java platform debugger architecture (JPDA)
http://download.oracle.com/javase/6/docs/technotes/guides/jpda/examples.html
来源:https://stackoverflow.com/questions/5410054/attach-to-another-jvm-and-listen-for-events-possible