简体   繁体   中英

How do I debug an external .jar file through eclipse?

It's hard to explain, but I'll try my best. There's a .jar file that opens up a GUI for a tournament environment. It's independent and I'm not given the source code. I need to code an agent in Java that competes in the tournament. When the .jar file opens, I can specify the path to my agent's class files in the GUI. This works fine. But I'm not sure how to debug this because the .jar file doesn't open in eclipse. I tried using external tools, which seems to run the .jar file but the GUI doesn't open up, so I can't specify the path to the agent. The tournament environment documentation doesn't really provide instructions to operate it without the GUI, so I really need to use just the GUI. Any way I can run this file through eclipse, so I can see how my own agent works with the environment and test/debug accordingly?

Additional info - this .jar also acts as a library which I was able to import into Eclipse without any issues.

It's hard to tell all of what's going on here, but there are a few things that can help.

First, you can start your app with the jar using command-line options like this:

-Xdebug -Xnoagent -Xrunjdwp:transport=dt_socket,address=8453,server=y,suspend=n

Note that if you need to debug the startup code, you'll need to set "suspend=y", so the app will pause startup until you connect from the debugger.

In Eclipse, connect on port 8453.

Second, stepping through code that you don't have the source code for is not insurmountable. Install the "jd-eclipse" plugin, which you can get at http://jd.benow.ca/ . That will make that possible.

I've been using the JAD Eclipse plugin to reverse engineer jar libraries on the fly. http://jadclipse.sourceforge.net/wiki/index.php/Main_Page

However, it is worth to note that the decompiled source code does not exactly match the line numbers in stack traces.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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