Jar Work in a Shell Script

Apr 20th, 2006No Comments

Yep, my continuing silence means that I’ve been busy in the real world. But here’s something that I cooked up that maybe useful.

It seems that we screwed up our deployment descriptors in Weblogic and Weblogic 8.1 just complained and went on with the world. Well, a customer decided to try Weblogic 9.1 and it not only complains — our stuff just doesn’t work. A developer fixed it in source control, but we can’t send a customer code that’s in there — so I had to manually update our release EAR file (which has many .war’s and our EJB .jar in it) and re-package it. Of course, all I was given was new EAR file — nothing else.

Once I figured out what files from needed to be updated from each EAR file, I needed to replace them in the release EAR. Of course, this process was tedious:

  1. Open Development EAR
  2. Open Release EAR
  3. Open each WAR in each an and copy files from Development to Release
  4. Rebundle each WAR
  5. Do something similar to the EJB jar

With five applications bundled in our EAR, this is painful and error-prone. I know — I tried to do it by hand. After fighting this for an hour, I took another thirty minutes and wrote a script. dir is my exploded release EAR and otherdir is the explode Development EAR with the files I needed to copy in a directory under the same name.

Confused? Well, say under dev.ear we had an WAR named webapp.war. So I created a directory called webapp and used jar to manually put in the WEB-INF/web.xml file. That way, everything was separated.

Okay, so now that we have the setup, here is the script:

#!/bin/sh

dir=wpServerPlus
otherdir="$HOME/Projects/WorkPoint/future-WP34/lib/wpServerPlus"

for x in $dir/wp*.war; do
    fname=`basename $x`
    dirname="$otherdir/${fname%%.*}"
    tempdir="$dir/${fname%%.*}"

    for d in $dirname/*; do

	newfiles=""
	mkdir $tempdir
	echo cp $x $tempdir
	cp $x $tempdir
	cd $tempdir

	for n in $dirname/*; do
	    cp -r $n .
	    newfiles="$newfiles `basename $n`"
	done

	jar uvf $fname $newfiles
	cp $fname ..
	cd ../..
	rm -rf $tempdir

    done

done

With the WAR files done this way, I could easily do the EJB jar by hand.

Also, this is the first time I’ve done string chopping in Bash (note the ${AD%%war} stuff). It’s not easy to figure out, but it’s useful. I used this developerWorks article to help me grok it.

Leave a Reply

You must be logged in to post a comment.