Morteza Malvandi
Morteza Malvandi

Reputation: 1724

How rebuild a jar file?

I have a jar file with following directory:

css/
images/
js/
META-INF/
atlassian-plugin.xml
jira_rtl.properties
LICENSE

I want to change the file.css in css directory and then rebuild the jar file.

How Can I do this in Windows 8.1 OS?

Upvotes: 0

Views: 9715

Answers (2)

Nikos M.
Nikos M.

Reputation: 8325

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].jar to [filename].zip and vice-versa.

Some archivers like 7-zip even enable you to directly edit from the program and after you save your edits it will automatically update your archive (in this case a zip with a .jar extension). So this is even easier than unpacking all files and packing them again.

There are rare cases where the order of files in the jar matters (OSGi bundles for example), so you have to be careful. But I would say in 99,9% the order does not matter at all.

Java ARchive (.jar) format is (just) a zipped file with same format as .zip, that is why this can be done. The same .zip format is used in other archive formats (for example .swc for ActionScript/Flash)

Upvotes: 1

Sathish
Sathish

Reputation: 5173

Use the following command to update the file via Java's jar utility,

<JAVA_HOME>/bin/jar -uvf <jar-file-name> <modified file path>

In your case lets say the jar file name is simple.jar,

<JAVA_HOME>/bin/jar -uvf simple.jar css/*

Upvotes: 4

Related Questions