Conversion of class file to Java files

Rajesh Kumar picture Rajesh Kumar · Jul 20, 2012 · Viewed 9k times · Source

I have one War files (a Java application) consist of 64 class file along with image/CSS/JS files. I have lost the source of this war file. Now I want to do some changes in code. I am looking for some expert advice from community on following questions.

  1. Is there best way to convert .class files to .java file without losing any section of code?
  2. What are the tools if any for this task?
  3. What are challenges/drawbacks of converting .class files to .java files to recreate war file?

Answer

Anirudh Ramanathan picture Anirudh Ramanathan · Jul 20, 2012
  1. Conversion to Java Bytecode is almost completely reversible. As @StephenC said, In the regenerated sources, you will lose comments, names of local variables etc. It might not compile right away but you should be able to get it to compile again, with a little modification.

  2. You need a Java Decompiler to do that. Try JD-GUI or DJ Java Decompiler

  3. In case you obfuscated your sources, the sources you recover will not be harder to understand and reverse engineer. Otherwise, with just a little tinkering, you should be able to get back your sources.