Friday 17 February 2012

JAVA DECOMPILER

It's good to be detail oriented  when one works in technology. 
I was exploring ODI sdk and was curious to know how one of the plugins for ODI was written. 
I was looking for a decompiler which could decompile a  .class(bytecode) file into native java code. 
One of the decompiler plugin for java ide Eclipse is available at SourceForge.net. 
For decompiling .class file to .java one needs:

1.  A plugin(JadClipse) for Eclipse which is available at  sourceforge.net for download:   here
2.  The JAD executable available here

3. copy 1 to to plugins folder of Eclipse install. 
4. place 2( JAD executable) to a location (say c:\jad_home\) and set it in the PATH environment variable. 
or 

Go to Eclipse->Window->Preferences->Java->JadClipse and set the "Path to decompiler" as the place where JAD.exe exists.




Note: if you don't see Eclipse->Window->Preferences->Java->JadClipse it means the JadClipse plugin is not installed correctly. 

5. A restart of Eclipse is required after the configuration. 

6. Add the .jar file containing the classes to be reverse engineered to a project as external library
  select a project->Right click->Build Path-> Configure Build Path opens below dialog box:


7. Once the .jar file is added to the project. Select a class file on the Project explorer by expanding Referenced Libraries and any .jar file within it and then select a .class file. Press F3 to see the decompiled java code of the .class file selected. 

Alternatively by placing the cursor on a Java class name in the right side code window and pressing F3 also displays the decompiled java code of the class selected!