Question

I have a jar file, and I need to edit a particular class and save it back into the jar file. I tried different decompilers, but I'm not able to save back to the jar.

I tried Eclipse along with JADCLIPSE to decompile. By using that, I can see the decompiled class file, but I'm unable to edit it. Could anyone please help me to resolve this?

Was it helpful?

Solution

I use JD-GUI to decompile .jar's, this has an option to export all the decompiled classes. If the .jar you are decompiling has not been obfuscated etc this source should be re-compilable (otherwise you will need to go about it by bytecode editing).

Once you have extracted the classes, you need to ensure when you compile you compile with the -CP parameter pointing at .;MyJar.jar so that dependencies within the .jar can be found at compile.

After you have recompiled and have your new .class file/s, open the .jar with 7z and replace the old .class file/s with your new one. You can do this step with the command line jar tool but 7z makes it easier. Again if the jar was obfuscated and class files have identical names with only case sensitive differences you may need to use Linux to reinsert the .class file. (probably possible on Windows, but I've never looked into it too deeply).


I previously decompiled this Java program to add a commandline interface, you can probably find the link in the comments;

http://ninjacave.com/jarsplice

OTHER TIPS

then there are lot of free utilities available like WinZip , 7-ZIP you can use them.

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.

Thanks

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top