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.
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.
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With