有没有办法比较两个 Java 战争文件
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/2535089/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Is there a way to compare two Java war files
提问by nzpcmad
We built some war files for our web server a while back and have now rebuilt them.
不久前,我们为我们的 Web 服务器构建了一些战争文件,现在重新构建了它们。
To ensure that nothing has changed (and as a quality check), we tried to compare them using WinMerge. The differences we can see look like they are due to some kind of meta data e.g. the files being built on different dates?
为确保没有任何变化(并作为质量检查),我们尝试使用 WinMerge 对它们进行比较。我们可以看到的差异看起来像是由于某种元数据导致的,例如在不同日期构建的文件?
The difference in the lines seems to be consistent e.g.
线条的差异似乎是一致的,例如
?d}<
?d}<
and
和
3Ze<
3泽<
The war files are still both the same size.
战争文件的大小仍然相同。
Is there a way to compare them that strips out the meta data such as date?
有没有办法比较它们以去除元数据(例如日期)?
采纳答案by Kris
WAR files are basically Zip files. Why not extract the contents and compare each file in turn? This avoids any meta-data that is a part of the WAR file. You can also figure out what the differences actually are if any are discovered.
WAR 文件基本上是 Zip 文件。为什么不提取内容并依次比较每个文件?这避免了作为 WAR 文件一部分的任何元数据。如果发现任何差异,您还可以弄清楚实际差异是什么。
回答by laher
It should be easier if you unzip them first and then compare folders.
如果您先解压缩它们然后比较文件夹应该会更容易。
In Windows you could just use the 'jar' executable which comes with the jdk
在 Windows 中,您可以使用 jdk 附带的“jar”可执行文件
jar -xvf xxxx.war
Then you can use WinMerge to compare the 2 folders.
然后您可以使用 WinMerge 来比较 2 个文件夹。
Hope this helps
希望这可以帮助
回答by Venkat Sadasivam
you can use eclipse to compare jar/war files. http://www.javalobby.org/java/forums/m91839415.html
您可以使用 eclipse 来比较 jar/war 文件。 http://www.javalobby.org/java/forums/m91839415.html
The link does not mention war file. I'm using Indigo, it seems eclipse only support jar comparison hence I have to rename the war extension to jar to get eclipse to do the structural comparison.
该链接没有提到战争文件。我正在使用 Indigo,似乎 eclipse 只支持 jar 比较,因此我必须将 war 扩展名重命名为 jar 以使 eclipse 进行结构比较。
回答by Shanaka Jayalath
Use "Beyond Compare" free trial... (or buy it) I think it is the only tool that can do that.
使用“Beyond Compare”免费试用...(或购买)我认为这是唯一可以做到这一点的工具。
回答by Lewis B
You can configure WinMerge to compare zip files (and by the way, .WAR files), if you install the 7zip plugin of WinMerge. Keep in mind that is not very easy to install, you must install the plugin, it is made of .dll and must be extracted in a folder.... Honestly I dont remember how I did it. I believed at the end I used the standalone installer ooption and use 9.20 version of the plugin.
如果您安装了 WinMerge 的 7zip 插件,您可以配置 WinMerge 来比较 zip 文件(顺便说一下,.WAR 文件)。请记住,这不是很容易安装,您必须安装插件,它由 .dll 组成,必须解压缩到一个文件夹中......老实说,我不记得我是怎么做到的。我相信最后我使用了独立安装程序 ooption 并使用了 9.20 版本的插件。
Althoug some times, winmerge tells me there are diferences in .class files, it hightlighs the binary line, but i dont see anydiference. At least you can compare war folder structure at least.
尽管有时,winmerge 告诉我 .class 文件存在差异,它突出了二进制行,但我看不到任何差异。至少您至少可以比较 war 文件夹结构。
回答by slm
I generally use an approach like this and run 2 unzip commands and diff the output as required. For example I need to compare 2 Java WAR files.
我通常使用这样的方法并运行 2 个解压缩命令并根据需要区分输出。例如,我需要比较 2 个 Java WAR 文件。
$ sdiff --width 160 \
<(unzip -l -v my_num1.war | cut -c 1-9,59-,49-57 | sort -k3) \
<(unzip -l -v my_num2.war | cut -c 1-9,59-,49-57 | sort -k3)
Resulting in output like so:
导致输出如下:
-------- ------- -------- -------
Archive: Archive:
-------- -------- ---- -------- -------- ----
48619281 130 files | 51043693 130 files
1116 060ccc56 index.jsp 1116 060ccc56 index.jsp
0 00000000 META-INF/ 0 00000000 META-INF/
155 b50f41aa META-INF/MANIFEST.MF | 155 701f1623 META-INF/MANIFEST.MF
Length CRC-32 Name Length CRC-32 Name
1179 b42096f1 version.jsp 1179 b42096f1 version.jsp
0 00000000 WEB-INF/ 0 00000000 WEB-INF/
0 00000000 WEB-INF/classes/ 0 00000000 WEB-INF/classes/
0 00000000 WEB-INF/classes/com/ 0 00000000 WEB-INF/classes/com/
...
...
I prefer this approach since it doesn't require space to uncompress the files and then compare them.
我更喜欢这种方法,因为它不需要空间来解压缩文件然后比较它们。
回答by Marcus Junius Brutus
Just use pkgdiff
:
只需使用pkgdiff
:
pkgdiff a.war b.war
Readily available in Linux, fairly parsable output (you can also check the status code from a bash script). It also generates an awesome HTML report.
在 Linux 中很容易获得,相当可解析的输出(您也可以从 bash 脚本检查状态代码)。它还生成一个很棒的 HTML 报告。