Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I update one file in a jar without repackaging the whole jar?

Tags:

I have a .jar file called myfile.jar. Inside this jar file is a folder called images. Inside this folder called images, I have an image called hi.png. I want to update that image with a new version of that image, which is also called hi.png. I do not want to extract all of the files from the single jar file and then repackage them, I just want to update the image. So, I go to command line as usual, type a few lines of code, and then I do this command:

jar uf myfile.jar -C images hi.png 

What I hoped to do with that command was to replace the old hi.png with the new hi.png. But, it gives me this error:

images\hi.png : no such file or directory 

What do I do to fix this?

Extra info: I can not use something like WinRAR, I have to do this with command line.

like image 570
Bobby C Avatar asked Dec 11 '11 01:12

Bobby C


People also ask

How do you update a JAR file?

The Jar tool provides a u option which you can use to update the contents of an existing JAR file by modifying its manifest or by adding files. In this command: The u option indicates that you want to update an existing JAR file.

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.

How do I recreate a JAR file?

Use WinRAR (or similar) to unzip the . jar file and replace the files you need and then re-zip it (using a . jar file extension). You may need to rename [filename].


2 Answers

-C is changing the local directory, and is looking for hi.png there. It's not controlling where you're trying to inject it into the JAR file.

I would try making a new directory called images, moving your local hi.png into that, making images a child directory of your current working directory, then just run this:

jar uf myfile.jar images\hi.png 
like image 64
ziesemer Avatar answered Dec 15 '22 00:12

ziesemer


The simplest way to do is using 7-zip software. For

  1. Editing a file:

    • Open the jar file 7-zip | open archive
    • goto the file e.g. /Meta-Inf/xyz.conf
    • right mouse click and select 'open inside' option
    • edit the file and save the file
    • close the 7-zip console and it's done.
  2. For adding/replacing/removing a file.

    • Follow the first two steps till you reach the desired folder.
    • Removing: delete the file
    • Adding: Drag and drop the file to the 7-zip console.
    • close the console and it's done.
like image 40
iankits Avatar answered Dec 15 '22 01:12

iankits