How to decompile a Java class inside a JAR file

Posted on February 6, 2009 at 5:39 am

We usually get java programs as compiled jar (or Java archive) files.  Since a jar file is essentially just a ZIP file so you can unzip it to see the files that make up the program.  The idea is to optimize the download times since jar files are compressed files.  

Why would you unpack a jar file?  There are possible reasons like you lost the source code and you want to rebuild the classes with some code updates or you just want to see how a certain class is implemented because you  are curious or lazy and just want to reuse someone else’s code.  Whatever the reason, good or bad, I will show you how to unpack a jar file and decompile the classes inside it.

Get the installer of the Cavaj decompiler, run it and then follow the steps below:

Step 1: Unzip the jar file using WinZip or WinRAR.  In the example below I will use classes12.jar which is a driver class for handing Oracle connectivity.  You may use any jar file for this tutorial.

Step 2: Once you unzipped the files browser through them and open any class file with Cavaj:

image

At this point you will see the source code of the class.  The left side has the tree of all the methods of the class while the right side has the source code. 

Programmers who need to get their source codes from class and jar files will surely benefit from this tool.  Now that you see how easy it if for a software like Cavaj to decompile your code, how are you going to protect your code from such intrusion? 

There are ways to handle that and one is to not allow physical access to your jar files.  If you can’t help but distribute your jar files then you might want to look at several code obfuscation techniques discussed here.  Also there are tools available that will help you obfuscate code.  We will show them to you on later posts so make sure to subscribe to our RSS feeds if you have not yet done so.

Ben Carigtan shows you how it’s done.

» Filed Under Free Software Downloads

Related Posts

Comments

Please post your comments/suggestions!