Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Replace a single file from jar file

I need to replace a single class file from a jar file. The jar file is quite big and every time I don't want to extract it and replace manually. I want to automate this procedure. Can someone please help me on this. When jar file is extracted below folders are created :

  1. render
  2. classes
  3. com

I need to go inside "com/cgp/f1/cmmi/" folder and replace a class file inside it.

Things I tried :

  1. zip file.jar com/cgp/f1/cmmi/services.class Services.class
  2. jar uf file.jar com/cgp/f1/cmmi/ services.class
    jar -uf file.jar com\cgp\f1\cmmi\ services.class
    jar uf file.jar com/cgp/f1/cmmi/services.class services.class

The error I am getting is :

when using jar command
com\cgp\f1\cmmi\ : no such file or directory

when using zip command :
zip warning: name not matched: com\cgp\f1\cmmi\Services.class

can some one please guide me where I am going wrong.

like image 834
programoholic Avatar asked Jul 04 '26 02:07

programoholic


1 Answers

Maybe the jar -uf found here could help you: How to update one file in a zip archive

If graphical apps are an option, you could use winrar or 7-zip to replace the class. You don't need to extract the jar file to make this work. Just open the jar with one of those apps, go to de directory where is the class file to be replaced, drag-and-drop the new file to replace the old one and save.

like image 133
Carlos Nantes Avatar answered Jul 06 '26 15:07

Carlos Nantes



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!