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.
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.
decompile.zipand extract the contents into a path on the file system that doesn’t contain spaces. Eg.
- You should be able to see a directory structure as shown below.
- 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\srcfolder is empty.
- The utility decompiles each of the
.classfile found in
classesdirectory and places the
.javafiles under the
srcdirectory. 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.