Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

How to Extracting a *.war via "jar -xf" to another directory  RSS feed

 
Diego Bowen
Ranch Hand
Posts: 50
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello I'm have the following:
cd /home/temp/
ls
diego.war(a war file called diego) diego(a directory called diego)

If i do the following:
jar -xf diego.war

It will extract its contents into /home/temp...however I want it in /home/temp/diego.

How can i extract the contents not in the current dir but one of my choosing?

UNIX....I'm doing this via rpm spec file. Thanks
 
Diego Bowen
Ranch Hand
Posts: 50
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I usually answer my own questions....in any event

unzipping will do the same thing and it provides an option to define alternate directories for the extraction:

unzip foo.war -d /home/foo
 
Carol Enderlin
drifter
Ranch Hand
Posts: 1364
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I usually do it the other way around. cd to the directory of interest and then unjar the desired file from its location.

cd /home/temp/diego

jar -xf /home/temp/diego.war

or

jar -xf ../diego.war
 
Osuwari Inu
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I know this is an ancient post, but I just made a small script to recursively explode an ear/war/jar/zip and thought it might be of use to someone finding this thread.

#!/bin/sh
#

if [ ! "$1" ];
then
echo No ear file specified.
exit 1
fi

if [ ! -f "$1" ];
then
echo Specified file does not exist or is not a file.
exit 1
fi

if [ ! "$2" ];
then
echo No destination directory specified.
exit 1
fi

if [ ! -d "$2" ];
then
echo Destination directory does not exist or is not a directory.
exit 1
fi


unzip "$1" -d "$2"
find "$2" -type f -name "*.war" -exec mkdir "{}.exploded" ';'
find "$2" -type f -name "*.war" -exec "$0" '{}' "{}.exploded" ';'
find "$2" -type f -name "*.jar" -exec mkdir "{}.exploded" ';'
find "$2" -type f -name "*.jar" -exec "$0" '{}' "{}.exploded" ';'
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!