jar文件:为什么提取然后压缩一个jar文件创建一个不同大小的文件到原来的? [英] Jar files: why does extracting then compression a jar file create a file of a different size to the original?

查看:190
本文介绍了jar文件:为什么提取然后压缩一个jar文件创建一个不同大小的文件到原来的?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图在提取的Eclipse插件jar文件中编辑一个字节。我注意到,在将文件重新压缩为jar后,生成的文件大于原始文件(仅1%),并且该插件不起作用。 Eclipse启动,但在选择工作区后静默关闭。然后回滚到原来的插件,可以成功启动。



然后我尝试解压缩,然后压缩插件(不改变任何东西),结果的jar文件仍然大于原来的,也没有工作。

  $ jar -xf temp / in.jar 

$ p $ cf out.jar temp / *

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

我猜这可能是因为时间戳被改变,但是我并不认为这会阻止eclipse接受它。



所以我的问题:有没有办法解压缩一个jar,改变一个字节,压缩它,而不会改变jar?



我使用Ubuntu 10.04 - 64位:

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

查看jar的标签le,似乎有一个不同的顺序:

  $ 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

有没有办法在jar内订购不同?

解决方案

如果一个文件被修改,则在重新压缩后获取不同的大小是正常的。但是如果没有任何修改,也许您在这两个档案中都没有相同的根目录。



运行以下两个命令并在此发布结果(仅第一行):

  jar tf in.jar 
jar tf out.jar

这些命令以Jar文件的路径列出所有文件。



仅使用以下命令更新修改的文​​件:

  jar uf in.jar TheFileYouModified 

TheFileYouModified必须与JAR文件中相同的路径。例如,替换您在/ tmp / injar中解压缩的com / android / Example.class,并修改:

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


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?

解决方案

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

这篇关于jar文件:为什么提取然后压缩一个jar文件创建一个不同大小的文件到原来的?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆