(Remote) debug is a great way to trouble-shooting, to figure out how the code works. But sometimes we only have the jars, no source code. For example the code is closed or proprietary, no where to get the sourc code.
Luckily, we can use JDEclipse-Realign to easily debug classes without sources in Eclipse.
1. Install and Configure JDEclipse-Realign in eclipse
Install via JDEclipse-Realign update site http://mchr3k-eclipse.appspot.com/.
Click "Window" -> "Preferences", type "File Association". Select "class without source", in the dialogue below,change the default from "Class File Viewer [Decompiled]" to "Class File Editor".
2. Find jars contained classes which we want to debug
In linux, Use grep -r -s full_class_name * to find the jar.
3. Create a java project with the jars
Create a java project in Eclipse, add the jar(related jars) into the project's build path.
Now if we right click on the jar, select "Attach Source", we can see "Decompiled Source" is selected..
4. Enable remote debug
Add the -Xdebug -Xrunjdwp:transport=dt_socket,address=1044,server=y,suspend=y in JVM options to remote java application.
Then configure Eclipse for remote debugging by click "Run" -> "Debug Configuration", then create a new "Remote Java Application", enter the host, and port number: 1044 in this case, be sure to slect the previously-created project in project textbox.
5. Add breakpoints in compiled classes and Run
After add breakpoints, run remote application: remote application will stop and wait for remote debut client to connect to port 1044.
Run remote debug in Eclipse, now the application will stop at breakpoints.
Other tools
JD-GUI from http://jd.benow.ca/
CFR
- A decompiler that supports Java 8 language features, including lambda expressions and me
thod references.
java -jar cfr.jar class_or_jar_file [method] [options]
Resources
Mchr3k - JDEclipse-Realign
JDEclipse-Realign Github
JD-GUI
Luckily, we can use JDEclipse-Realign to easily debug classes without sources in Eclipse.
1. Install and Configure JDEclipse-Realign in eclipse
Install via JDEclipse-Realign update site http://mchr3k-eclipse.appspot.com/.
Click "Window" -> "Preferences", type "File Association". Select "class without source", in the dialogue below,change the default from "Class File Viewer [Decompiled]" to "Class File Editor".
2. Find jars contained classes which we want to debug
In linux, Use grep -r -s full_class_name * to find the jar.
3. Create a java project with the jars
Create a java project in Eclipse, add the jar(related jars) into the project's build path.
Now if we right click on the jar, select "Attach Source", we can see "Decompiled Source" is selected..
4. Enable remote debug
Add the -Xdebug -Xrunjdwp:transport=dt_socket,address=1044,server=y,suspend=y in JVM options to remote java application.
Then configure Eclipse for remote debugging by click "Run" -> "Debug Configuration", then create a new "Remote Java Application", enter the host, and port number: 1044 in this case, be sure to slect the previously-created project in project textbox.
5. Add breakpoints in compiled classes and Run
After add breakpoints, run remote application: remote application will stop and wait for remote debut client to connect to port 1044.
Run remote debug in Eclipse, now the application will stop at breakpoints.
Other tools
JD-GUI from http://jd.benow.ca/
CFR
- A decompiler that supports Java 8 language features, including lambda expressions and me
thod references.
java -jar cfr.jar class_or_jar_file [method] [options]
Resources
Mchr3k - JDEclipse-Realign
JDEclipse-Realign Github
JD-GUI