Stu
Stu

Reputation: 1567

Jar files: why does extracting then compression a jar file create a file of a different size to the original?

I was trying to edit a single byte in an extracted Eclipse plugin jar file. I noticed that after I re-compressed the files as a jar, the resultant file was larger than the original (only 1%) and that the plugin didn't work. Eclipse booted, but shut down silently after selecting a workspace. Rolling back to the original plugin allowed it to start successfully.

I then tried uncompressing, then compressing the plugin (not changing anything) and the resultant jar file was still bigger than the original, and also didn't work.

$ jar -xf temp/in.jar

then

$ jar -cf out.jar temp/*

$ du in.jar out.jar
4216    in.jar
4236    out.jar

I guess this might be due to timestamps being changed, but I didn't think that this would stop eclipse from accepting it.

So my question: Is there a way to uncompress a jar, change a byte, and compress it without changing the jar significantly?

I'm using Ubuntu 10.04 - 64 bit:

Linux user 2.6.32-38-generic #83-Ubuntu SMP Wed Jan 4 11:12:07 UTC 2012 x86_64 GNU/Linux

When looking at the jar's table, there appears to be a different order:

$ jar tf in.jar | head -n 5
META-INF/
META-INF/MANIFEST.MF
com/
com/android/
com/android/ide/

$ jar tf out.jar | head -n 5
META-INF/
META-INF/MANIFEST.MF
about.html
about.ini
about.properties

Is there a way to order them differently within the jar?

Upvotes: 2

Views: 5434

Answers (1)

LD.
LD.

Reputation: 418

Obtaining a different size after recompression is normal if one file has been modified. But if nothing has been modified, maybe you haven't the same root directory in both archives.

Run the following two commands and post the result here (the first lines only):

jar tf in.jar
jar tf out.jar

These commands list all files in Jar files with their path.

Have you tried to update only the modified file using the following command:

jar uf in.jar TheFileYouModified

TheFileYouModified must be the same path as in the JAR file. For example to replace com/android/Example.class you have extracted in /tmp/injar/ and modified :

jar uf in.jar -C /tmp/injar com/android/Example.class

Upvotes: 4

Related Questions