shell脚本批量替换jar包中Class文件

下面是shell脚本批量替换jar包中Class文件

#!/bin/sh

#JAVA home path set
JAVA_HOME=/usr/local/web/fit/WAS/install/61x/java
export PATH=${PATH}:${JAVA_HOME}/bin


#param 1 is jar file path. Sample path: /root/jar/app.jar
appJar=$1

#param 2 is folder path which stores class files. Sample path: /root/classfiles
filesTobeUpdated=$2
tempDir=$filesTobeUpdated/temp

echo "delete temp directory"
if [ -d $tempDir ]
then
   rm -rf $tempDir
fi

echo "create temp file path:"$path
mkdir $tempDir

for i in `ls -l $filesTobeUpdated|grep ^- | awk '{print $9}'`
do
echo "finding file:"$i
path=""
num=0
for j in `jar tf $appJar`
do
if [ `echo $j |grep -c $i` -gt 0 ];then
echo "found file"
path="$path
$j"
num=`expr $num + 1`
if [ $num -eq 1 ];then
pathForNum1=$j
fi
fi
done
echo $num

if [ $num -gt 1 ];then
    fileNum=0
    while [ $fileNum != 1 ]
    do
        echo "$path"
        echo "More than 1 file matched, input filePath:"
        read filePath
        fileNum=`jar tf $appJar $filePath | wc -l`
        #for k in `jar tf $appJar`
        #do
        #    if [ `echo $k |grep -c $filePath` -gt 0 ];then
        #    fileNum=`expr $fileNum + 1`
        #    fi
        #done
    done
    path=$filePath
elif [ $num == 0 ]; then
    echo "Looks like this is newly added file, input filePath:"
    read filePath
    echo $filePath
    path=$filePath
else
    path=$pathForNum1
fi

cd $tempDir
pathCut=$path

while [ `echo $pathCut |grep -c '/'` -gt 0 ]
do
        element=`echo $pathCut | awk -F '/' '{print $1}'`
        if [ ! -d $element ]
        then
           echo "directory is not exist, create:"$element
           mkdir $element
        fi
        cd $element
        pathCut=${pathCut#*/}
        echo "pathCut is:"$pathCut
done
cp -f $filesTobeUpdated/$pathCut $tempDir/$path

cd $tempDir
jar uf $appJar $path

echo "replace done"
done

echo "delete temp directory"
if [ -d $tempDir ]
then
   rm -rf $tempDir
fi

 

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值