Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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.

like image 315
Agung Pratama Avatar asked May 29 '13 05:05

Agung Pratama


People also ask

How do I remove a specific class from a jar file?

one more approach using winzip/winrar open your jar, go to the class location and just drag and drop updated class, close winrar/winzip and do not need to explod jar and then recrete jar...

How do you decompile a jar and edit it?

Before opening jar file just change the extension of jar to zip file and then extract that particular class file that you want to edit , then decompile it using any decompiler ,make the changes , compile it back and then finally put it back in the zip file. Hope it helps.


2 Answers

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/

like image 72
Juned Ahsan Avatar answered Oct 15 '22 13:10

Juned Ahsan


  1. Extend class and rewrite method removing bug

  2. Use JDEC to decompile and replace class ( http://jdec.sourceforge.net/ )

like image 31
Igor S. Avatar answered Oct 15 '22 13:10

Igor S.