How to remove class file in .jar file and change it with my own implementation

Agung Pratama picture Agung Pratama · May 29, 2013 · Viewed 33.8k times · Source

So, I have third party library, which is a .jar file. There are some classes in that jar. The problem is, there is one bug in one class in that .jar. I know it because I can decompile the jar file, to look at the java code, which is I am pretty sure, that class is the source of my program bug.

The idea is, I delete the class and replace it with my own class, but I dont know how.

Answer

Juned Ahsan picture Juned Ahsan · May 29, 2013

There are multiple ways to do this:

  1. Try to use winrar. You can open your jar in it, explore the directory containing the class file. You can delete and add class files.

  2. If you don't want to use winrar then do like this:

Extract the jar using this command

jar -xvf yourjar.jar

It will explode the jar. Delete the old class file and add your updated class file

Recreate the jar using the following command

jar -cvf yourjar.jar directoryofexploderjar/