Often we encounter situations where the only solution to a certain Java problem is to decompile the contents of an entire JAR file, edit the resulting the source, rebuild and repackage before using.

I searched a lot for decompilers which could recursively decompile multiple class files while preserving the package hierarchy, but in vain. So, I thought of writing a Windows batch script myself, to do what I was looking for. This script is also known as JAR decompiler or recursive JAD.

Download Recursive Java Decompiler 175 kB

I have used JAD for decompilation. JAD is an excellent decompiler which can be downloaded from the author’s website, http://www.kpdus.com/jad.html. It provides an executable, jad.exe which has various options to run the decompiler.

The following steps outline how to make use of the Recursive Decompiler Utility to successfully decompile a huge set of class files.

  • Download decompile.zip and extract the contents into a path on the file system that doesn’t contain spaces. Eg. D:\decompile.
  • You should be able to see a directory structure as shown below.
    Recursive tree
  • Extract the contents of the JAR file you would want to be recursively decompiled, into the folder decompile\classes. You may use any the command jar -xvf <jar> <dir> or any of the popular file compression softwares such as WinZip or WinRar to do the same.
  • Make sure the decompile\src folder is empty.
  • Run decompile.bat.
  • The utility decompiles each of the .class file found in classes directory and places the .java files under the src directory. This operation preserves the original class hierarchy.

Now you can edit the code, recompile, rebuild, repackage and start using it!

Note: Because this utility uses some advanced batch scripting commands, it works only on Windows XP or higher operating systems.

Comments


comments powered by Disqus