How to debug .class file in eclipse


There are so many open source framework/products available in market, many of the time as a developer we want to explore/debug the code from .class files to understand the  logic in depth.

Another case can be, when using some .jar in project we might have to change the implementation of a function but before making any changes we need to be sure that we understand existing implementation very correctly.

Without writing too much theory now I'll jump on how we can debug the .class file in eclipse.


Step 1)

  1. Open Eclipse -> Windows/Eclipse (if you have macbook) -> Preferences -> General -> Editors ->  Text Editors 
  2. Make sure "Show line numbers" checkbox is selected 


       

Step 2)

  1. Open Eclipse -> Windows/Eclipse (if you have macbook) -> Preferences -> General -> Editors ->  File Associations
  2. Click on *.class without source 
  3. Select Class Decompiler viewer and click on Default.
  4. Click Apply and Close.
          


Step 3)

  1. Open Eclipse -> Windows/Eclipse (if you have macbook) -> Preferences -> Java -> Decompiler. 
  2. Make sure "Align code for debugging" checkbox is selected.
  3. Make sure "Output original line numbers as comments" checkbox is selected.
  4. Restart eclipse 
          




Now you should be good to debug class files.

Comments