Skip to content

Instantly share code, notes, and snippets.

@tonvanbart
Last active September 19, 2016 11:42
Show Gist options
  • Save tonvanbart/2d2ab7df3b9677c799c9 to your computer and use it in GitHub Desktop.
Save tonvanbart/2d2ab7df3b9677c799c9 to your computer and use it in GitHub Desktop.
A small bash script to delete given set of jar files from the WEB-INF/lib of a given warfile.
#!/bin/bash
main() {
if [ "$#" -ne 2 ]; then
EXPLAIN
exit 0
fi
clean "$@"
}
function clean {
echo cleaning $1
for i in $(cat $2); do
zip -d $1 WEB-INF/lib/$i
done
}
function EXPLAIN {
cat << EOF1
Usage: $0 <warfile> <list-of-jarfiles>
Cleans the WEB-INF/lib folder of a given war file by deleting all the jar files
mentioned in the file pointed to by the second argument.
EOF1
}
main "$@"
@jsweeney-bb
Copy link

I believe for this bash script you should replace the f.zip arg with $1
( zip -d $1 WEB-INF/lib/$i )

also I pondered building upon it with an optional additive argument for adding additional jars but am unsure the added complexity is worthwhile. anyway it would be something like this:
( something like -> if [ "$#" -eq "3"]; then cat $3 | "s/^//WEB-INF/lib//" | zip -@ -u $1;fi )

added note: you can achieve the same removal of jars in your script without the for-loop by using the stdin option and appending a WEB-INF/lib prefix to each argument such that there is no for loop only the statement below:
cat $2 | sed "s/^//WEB-INF/lib//" | zip -@ -d $1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment