Create Jar using shell script

Hi Folks

I came up with peculiar requierement ..:slight_smile:

I have to jar special files types only from a number of child folders , and also exactly same as the child file path...sorry i will give an example

suppose i have following folder structure

# cd HTML/
total 0
drwxrwxr-x 2 johycage johycage 96 Sep 23 07:42 HTML
drwxrwxr-x 2 johycage johycage 96 Sep 23 07:42 XML
-rw-rw-r-- 1 johycage johycage 0 Sep 23 07:42 1.html
-rw-rw-r-- 1 johycage johycage 0 Sep 23 07:42 2.html
#cd HTML/
total 0
-rw-rw-r-- 1 johycage johycage 0 Sep 23 07:42 1.html
-rw-rw-r-- 1 johycage johycage 0 Sep 23 07:42 2.html
# cd ../XML/
total 0
-rw-rw-r-- 1 johycage johycage 0 Sep 23 07:42 1.xml
-rw-rw-r-- 1 johycage johycage 0 Sep 23 07:42 2.xml

And all i want is to create jar file which contain onlt html file types in the following manner.

# jar -tvf test.jar
0 Wed Sep 23 07:42:22 MST 2009 home/johycage/HTML/HTML/1.html
0 Wed Sep 23 07:42:28 MST 2009 home/johycage/HTML/HTML/2.html
0 Wed Sep 23 07:42:50 MST 2009 home/johycage/HTML/1.html
0 Wed Sep 23 07:42:56 MST 2009 home/johycage/HTML/2.html

I have achieved this using below simple scriipt. But as you know adding files using jar -uvf take much time if folder strcture is more complex. I am attaching the script below which used, Anyone have a better idea ???

touch test.jar
find /home/johnycage/HTML/ -name '*.html' -print| while read obj
do
jar -uvf test.jar $obj
done

cheers :slight_smile:

not sure if faster but try it:

find /home/johnycage/HTML/ -name "*.html" -exec jar -uvf test.jar {} \;

use '...jar -cvf... to create on the fly