简体   繁体   English

如何更新耳朵文件中的jar文件

[英]How to update jar file inside ear file

To update a jar file adding one class I can use it: jar -uvf 要更新添加一个类的jar文件,我可以使用它:jar -uvf

But I need to update a jar file inside a ear file, I tried the command below but it did not work: jar -uvf NameOfEarfile.ear:FolderName/NameOfJar.jar path/NameOfClass.class 但是我需要更新一个耳朵文件中的一个jar文件,我尝试了以下命令,但它不起作用:jar -uvf NameOfEarfile.ear:FolderName / NameOfJar.jar path / NameOfClass.class

Could someone help me on it? 有人可以帮我吗?

更好的方法是使用7zip软件。

Below is the code to update the ear/war/zip/jar file. 以下是更新ear / war / zip / jar文件的代码。 Before the execute of below code first convert the file into unix format. 在执行以下代码之前,请先将文件转换为Unix格式。

Copy the below code in TestUpdate.sh file and copy to unix server. 将以下代码复制到TestUpdate.sh文件中,然后复制到UNIX服务器。 Then use below commands. 然后使用以下命令。 Make sure the TestUpdate.sh, class files (which you want to copy inside the EAR/WAR/ZIP/jar) and the EAR/WAR/ZIP/jar file all are in same directory. 确保TestUpdate.sh,类文件(要在EAR / WAR / ZIP / jar中复制)和EAR / WAR / ZIP / jar文件都在同一目录中。

dos2unix TestUpdate.sh
. ./TestUpdate.sh FileNameWhichYouWantToUpdate # EAR/WAR/JAR/ZIP filename

#!/bin/bash

#LearName='TEST.ear'
LearName=$1
jar xf $LearName
for clas in *.class
do                    
  echo "Checking for $clas ..."
  for f in *.jar
    do
      result=$(jar tf $f | grep -w $clas)
      if [ -n "$result" ]; then
        echo "$f contains $result"

        Lp="${#clas}";
        Lr="${#result}";
        count=$((Lr-Lp));
        #echo $count
        dirC=${result:0:$count};
        echo "Directory $dirC"
        echo $dirC
        mkdir -p $dirC;
        echo "Copying $clas $dirC"
        cp $clas $dirC;
        echo "updating $f ..."
        jar ufv $f $result;
        file_write "updating $f ..."
        echo "Updating $LearName ..."

        jar ufv $LearName $f;
        echo "-----------------------------------------------"

        break
      fi                                             
    done
done    
rm -f *.jar ---- comment this line if your input file is .jar. If your input file is EAR/WAR/ZIP file then NO need to comment this line
rm -r *.war
rm -r META-INF
rm -f *.tmp
rm -r com

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM