Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Debug jar file in eclipse

Tags:

java

eclipse

jar

I have a jar file which is having some issue and I would like to debug it.

I created the application on eclipse. During dev phase I have done debug but with the source code. I wanted to debug jar file to find out the reason of error i.e. it could be source code I have is different from jar file or some jar file issue.

like image 238
user3459883 Avatar asked Mar 25 '14 13:03

user3459883


People also ask

How do I debug a file in Eclipse?

A Java program can be debugged simply by right clicking on the Java editor class file from Package explorer. Select Debug As → Java Application or use the shortcut Alt + Shift + D, J instead. Either actions mentioned above creates a new Debug Launch Configuration and uses it to start the Java application.

How do you create a breakpoint in a jar file?

Open project explorer and then expand your project. Then, look for maven dependencies and expand this tree view. Now, you can expand any jar file and see list of available classes and by pressing enter on any of them, Eclipse will decompile the source for you and you can set a breakpoint.


1 Answers

Seems like you want to remote debug.

The use this command to launch your jar:

java -Xdebug -Xrunjdwp:transport=dt_socket,address=8001,server=y,suspend=y -jar [JAR NAME HERE]

It should state something like :

Listening for transport dt_socket at address : 8001

And in eclipse, create a "Remote Java Application" debug configuration. The configuration is the only thing that matters as long as you have your project of interest open. Add the project[s] of interest that you would like to debug onto your source lookup path and set the port number to the configured address from the java launch command.

When you connect to your debug-enabled jar launch, your jar will halt execution and await debugger input upon hitting breakpoints. Just make sure you have the same version of the code in your jar and your eclipse.

like image 190
TTT Avatar answered Sep 22 '22 02:09

TTT