programoholic
programoholic

Reputation: 5194

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.

Upvotes: 2

Views: 19025

Answers (1)

Carlos N.
Carlos N.

Reputation: 1307

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.

Upvotes: 6

Related Questions