Jin
Jin

Reputation: 31

Debug jar which was not compiled with debug flag

I got some java .jar that was not compiled with debug flag. I want to use them in remote debuggin via IDE, so i decompiled them and added as source to the project. Sometimes brake points works wrong or dont even work at all.

The question is, what's the best methodology to debug .jar files that was not compiled with -g flag.

Upvotes: 1

Views: 205

Answers (2)

radistao
radistao

Reputation: 15504

In case it is a maven dependency it might be the -debug artifact is distributed separately. For example this HSQL dependency has both

  • hsqldb-2.5.0.jar
  • hsqldb-2.5.0-debug.jar

Unfortunately i didn't find a better way how to force IDE (Intellij IDEA) to download and use this artifact, so i downloaded it manually and replaces in ~/.m2/repository:

wget https://repo1.maven.org/maven2/org/hsqldb/hsqldb/2.5.0/hsqldb-2.5.0-debug.jar -O ~/.m2/repository/org/hsqldb/hsqldb/2.5.0/hsqldb-2.5.0.jar

More info:

Upvotes: 2

Chris Parker
Chris Parker

Reputation: 426

This can also happen if you remote debug code that has undergone changes and the changes are not deployed to the remote device. In a nutshell, the command in the jar does not correspond with the line number in your source.

Someone smarter than me might have a tricky answer, but for me the path of least resistance is to jar up the decompiled and then recompiled code from the jar file and debug that.

99.99% of the time I'm not interested in making actual changes to the jar so much as I simply want to know why my code doesn't work. Once I'm past that hurdle, I'll drop the original jar back in place and make sure my code still works. This a) (helps to make sure) that I don't violate the license, and b) doesn't make the project dependent on my code - since decompile/recompile can potentially change the behavior in subtle ways.

Be aware that some jar files have licenses such that simply decompiling the source and looking at it is a license violation. Although I usually don't worry too much about that since I have no intention of permanently using the decompiled and recompiled code, I just need to "see" it for a while. :)

Upvotes: 0

Related Questions