Thursday, 28 August 2014

Patching a WAR file

While working on testing a vendors latest software release they provided us with a hot fix to a single file in the WAR, or a whole new WAR with other fixes in. Since we'd only just completed a batch of testing we really didn't want to have to retest so the decision was taken to patch the WAR file. The original method appears to have been unpack the war using winzip and add in the patched file.

As an ex-unixadmin without winzip, it just didn't feel right and a swift bit of googling uncovered the 'u' option on jar which does exactly what I needed.

So, heres how to do it... assume your WAR is test.war, and you need to replace my/file inside it.

Get/check the path you need...
jar tvf ./test.war | grep "my/file"

Create a local tree structure to pop the file into...
mkdir -p ./my
cp ~/patches/my/file ./my/file


Now update the WAR with the new file...
jar -uf ./test.war my/file

Check its patched (i.e. is the file size updated?)
jar tvf ./test.war | grep "my/file"

No comments: