简体   繁体   English

如何通过Eclipse调试外部.jar文件?

[英]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. 有一个.jar文件可打开锦标赛环境的GUI。 It's independent and I'm not given the source code. 它是独立的,没有提供源代码。 I need to code an agent in Java that competes in the tournament. 我需要用Java编写一个可以参加比赛的代理。 When the .jar file opens, I can specify the path to my agent's class files in the GUI. 当.jar文件打开时,我可以在GUI中指定代理的类文件的路径。 This works fine. 这很好。 But I'm not sure how to debug this because the .jar file doesn't open in eclipse. 但是我不确定如何调试它,因为.jar文件无法在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. 我尝试使用外部工具,该工具似乎在运行.jar文件,但没有打开GUI,因此无法指定代理的路径。 The tournament environment documentation doesn't really provide instructions to operate it without the GUI, so I really need to use just the GUI. 比赛环境文档并没有提供没有GUI的操作说明,因此我只需要使用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? 我可以通过Eclipse运行此文件的任何方式,因此我可以看到自己的代理如何与环境一起工作并进行相应的测试/调试?

Additional info - this .jar also acts as a library which I was able to import into Eclipse without any issues. 附加信息-该.jar还充当了一个库,我可以毫无问题地将其导入Eclipse。

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: 首先,您可以使用以下命令行选项从jar启动您的应用程序:

-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. 请注意,如果需要调试启动代码,则需要设置“ suspend = y”,因此应用程序将暂停启动,直到从调试器连接为止。

In Eclipse, connect on port 8453. 在Eclipse中,连接端口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/ . 安装“ jd-eclipse”插件,您可以从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. 我一直在使用JAD Eclipse插件动态地逆向工程jar库。 http://jadclipse.sourceforge.net/wiki/index.php/Main_Page 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. 但是,值得注意的是,反编译的源代码与堆栈跟踪中的行号不完全匹配。

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

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