Monday, June 6, 2011

How To Update A File In A Jar/War Archive

Sometimes you want to update a file bundled in a jar or war archive (e.g. a config file).
In this post I am going to show how to update the file config/app-conf.xml in a war called frontend.war by using the jar-command.

To list the contents of our jar archive we type the following:

jar tf frontend.war

To extract the config file from the archive, type

jar xf frontend.war config/app-conf.xml

This creates a folder named config with the file app-conf.xml inside. Now you can edit the config file. After you are done editing the file you can update the archive by typing

jar uf frontend.war config/app-conf.xml

For having a quick look at the contents of a file you can use the unzip command:

unzip -q -c frontend.war config/app-conf.xml
(the c switch redirects output to stdout, the q(uiet) switch suppresses all other output. That's all!