How-to · Peek Pro

How to compare two JAR or WAR files on a Mac

Yesterday's build worked and today's does not. Before reading logs, it helps to know what is different inside the two artifacts: which files changed, and which libraries under WEB-INF/lib were added, removed or updated.

JAR WAR EAR WEB-INF/lib Peek Pro

With Peek

Compare two builds in one window

Compare is part of Peek Pro, which you can try free for 14 days.

1

Open the first build

Open one of the two archives in Peek.

2

Choose the other one

Choose Archive ▸ Compare With…, or Compare… on the archive's panel, and pick the second archive. A folder on disk works too.

3

Read what changed

Peek lists the entries that were added, removed and changed.

4

See the libraries by version

For a JAR, WAR or EAR, Peek lists the bundled libraries that were added, removed or updated, with the version each one states inside (pom.properties, then the manifest). A renamed JAR still shows its real version.

5

Open a changed file

A text file opens as a line diff; configuration files also show which keys changed. A changed .class opens as a listing of its declarations and instructions, with a summary of the methods and fields that changed.

From the Terminal

Diff the listings, then the contents

Comparing the lists of names is quick. Comparing contents means unpacking both.

# Which entries exist in one and not the other
diff <(unzip -Z1 old.war | sort) <(unzip -Z1 new.war | sort)

# Which files differ in content
unzip -q old.war -d old && unzip -q new.war -d new
diff -rq old new

The file name of a library is not its version: commons-io.jar can hold any release. And diff only tells you that two .class files differ, not what changed in them.

Questions

Where does Peek read a library's version from?

From what the library states inside itself: Maven's pom.properties first, then the JAR manifest. That is why a renamed file still shows the right version.

Can I compare a WAR against a folder?

Yes. Compare accepts an archive or a folder, which is useful for checking a build against an exploded deployment.

Does Peek decompile the classes to compare them?

No. It shows declarations and bytecode instructions, not Java source. That is enough to see which methods and fields changed.

Do both files have to be the same format?

No. You can compare a ZIP with a 7z, or a WAR with a folder; Peek compares the entries.

More how-to guides

Other things people do with a JAR or a WAR

Free to download

Open, browse and extract for free. Try Peek Pro for 14 days.

Peek is a native Mac app from the Mac App Store. Nothing is charged when the trial ends; Peek Pro is a one-time purchase, with no subscription and no account.