欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

解決jar包rar壓縮后無(wú)法運(yùn)行問(wèn)題

 更新時(shí)間:2024年05月20日 11:41:01   作者:Therf  
這篇文章主要介紹了解決jar包rar壓縮后無(wú)法運(yùn)行問(wèn)題,具有很好的參考價(jià)值,希望對(duì)大家有所幫助,如有錯(cuò)誤或未考慮完全的地方,望不吝賜教

jar包rar壓縮后無(wú)法運(yùn)行

報(bào)錯(cuò)為Failed to get nested archive for entry

java.io.IOException: Unable to open nested jar file

It has been compressed and nested jar files must be stored without compression,Please check the mechanism used to create your executable jar file

如果有出現(xiàn)該問(wèn)題,請(qǐng)檢查jar包壓縮時(shí)是否用壓縮軟件方式打開(kāi)。

如果丟進(jìn)去的是第三方j(luò)ar包或者更新后的引入lib包,復(fù)制到壓縮目錄時(shí)需要選擇壓縮方式,一定要選擇存儲(chǔ)方式。

不然rar默認(rèn)會(huì)給你再次壓縮,部署到linux后項(xiàng)目就無(wú)法正常運(yùn)行。

再次壓縮后大小與未壓縮時(shí)不一致,所以會(huì)報(bào)錯(cuò)。

一定要選擇存儲(chǔ)方式復(fù)制或覆蓋到壓縮目錄

java解壓縮zip和rar的工具類

     
import java.io.File;    
import java.io.FileOutputStream;    
     
import org.apache.tools.ant.Project;    
import org.apache.tools.ant.taskdefs.Expand;    
     
import de.innosystec.unrar.Archive;    
import de.innosystec.unrar.rarfile.FileHeader;    
     
public class DeCompressUtil {    
   /**  
    * 解壓zip格式壓縮包  
    * 對(duì)應(yīng)的是ant.jar  
    */   
   private static void unzip(String sourceZip,String destDir) throws Exception{    
       try{    
           Project p = new Project();    
           Expand e = new Expand();    
           e.setProject(p);    
           e.setSrc(new File(sourceZip));    
           e.setOverwrite(false);    
           e.setDest(new File(destDir));    
           /*  
           ant下的zip工具默認(rèn)壓縮編碼為UTF-8編碼,  
           而winRAR軟件壓縮是用的windows默認(rèn)的GBK或者GB2312編碼  
           所以解壓縮時(shí)要制定編碼格式  
           */   
           e.setEncoding("gbk");    
           e.execute();    
       }catch(Exception e){    
           throw e;    
       }    
   }    
   /**  
    * 解壓rar格式壓縮包。  
    * 對(duì)應(yīng)的是java-unrar-0.3.jar,但是java-unrar-0.3.jar又會(huì)用到commons-logging-1.1.1.jar  
    */   
   private static void unrar(String sourceRar,String destDir) throws Exception{    
       Archive a = null;    
       FileOutputStream fos = null;    
       try{    
           a = new Archive(new File(sourceRar));    
           FileHeader fh = a.nextFileHeader();    
           while(fh!=null){    
               if(!fh.isDirectory()){    
                   //1 根據(jù)不同的操作系統(tǒng)拿到相應(yīng)的 destDirName 和 destFileName    
                   String compressFileName = fh.getFileNameString().trim();    
                   String destFileName = "";    
                   String destDirName = "";    
                   //非windows系統(tǒng)    
                   if(File.separator.equals("/")){    
                       destFileName = destDir + compressFileName.replaceAll("\\\\", "/");    
                       destDirName = destFileName.substring(0, destFileName.lastIndexOf("/"));    
                   //windows系統(tǒng)     
                   }else{    
                       destFileName = destDir + compressFileName.replaceAll("/", "\\\\");    
                       destDirName = destFileName.substring(0, destFileName.lastIndexOf("\\"));    
                   }    
                   //2創(chuàng)建文件夾    
                   File dir = new File(destDirName);    
                   if(!dir.exists()||!dir.isDirectory()){    
                       dir.mkdirs();    
                   }    
                   //3解壓縮文件    
                   fos = new FileOutputStream(new File(destFileName));    
                   a.extractFile(fh, fos);    
                   fos.close();    
                   fos = null;    
               }    
               fh = a.nextFileHeader();    
           }    
           a.close();    
           a = null;    
       }catch(Exception e){    
           throw e;    
       }finally{    
           if(fos!=null){    
               try{fos.close();fos=null;}catch(Exception e){e.printStackTrace();}    
           }    
           if(a!=null){    
               try{a.close();a=null;}catch(Exception e){e.printStackTrace();}    
           }    
       }    
   }    
   /**  
    * 解壓縮  
    */   
   public static void deCompress(String sourceFile,String destDir) throws Exception{    
       //保證文件夾路徑最后是"/"或者"\"    
       char lastChar = destDir.charAt(destDir.length()-1);    
       if(lastChar!='/'&&lastChar!='\\'){    
           destDir += File.separator;    
       }    
       //根據(jù)類型,進(jìn)行相應(yīng)的解壓縮    
       String type = sourceFile.substring(sourceFile.lastIndexOf(".")+1);    
       if(type.equals("zip")){    
           DeCompressUtil.unzip(sourceFile, destDir);    
        }else if(type.equals("rar")){    
            DeCompressUtil.unrar(sourceFile, destDir);    
        }else{    
            throw new Exception("只支持zip和rar格式的壓縮包!");    
        }    
    }    
}  

修改jar文件,重新打包

報(bào)錯(cuò)

Caused by: java.io.IOException: Unable to open nested jar file 'BOOT-INF/lib/xxxx-0.0.1-SNAPSHOT.jar'
 at org.springframework.boot.loader.jar.JarFile.getNestedJarFile(JarFile.java:261)
 at org.springframework.boot.loader.jar.JarFile.getNestedJarFile(JarFile.java:247)
 at org.springframework.boot.loader.archive.JarFileArchive.getNestedArchive(JarFileArchive.java:109)
 ... 4 more
Caused by: java.lang.IllegalStateException: Unable to open nested entry 'BOOT-INF/lib/xxxx-0.0.1-SNAPSHOT.jar'. It has been compressed and nested jar files must be stored without compression. Please check the mechanism used to create your executable jar file
 at org.springframework.boot.loader.jar.JarFile.createJarFileFromFileEntry(JarFile.java:287)
 at org.springframework.boot.loader.jar.JarFile.createJarFileFromEntry(JarFile.java:269)
 at org.springframework.boot.loader.jar.JarFile.getNestedJarFile(JarFile.java:258)
 ... 6 more
 
Socket error Event: 32 Error: 10053.
Connection closing...Socket close.

處理方案

方案一:

解壓jar文件

  • jar -xvf ./*.jar
  • jar -xf  jar文件

修改解壓后后的文件

重新打包

  • jar -cfM0 *.jar ./

方案二:

  • winrar或7zip添加文件的時(shí)候, 將選擇壓縮方式由"標(biāo)準(zhǔn)"改為存儲(chǔ)(Store)

總結(jié)

以上為個(gè)人經(jīng)驗(yàn),希望能給大家一個(gè)參考,也希望大家多多支持腳本之家。

  • Shell腳本管理Java應(yīng)用程序的高效方法

    Shell腳本管理Java應(yīng)用程序的高效方法

    在軟件開(kāi)發(fā)中,管理和監(jiān)控 Java 應(yīng)用程序的運(yùn)行狀態(tài)變得愈加重要,本文將分享一個(gè)自用的簡(jiǎn)單但高效的 Shell 腳本,幫助輕松管理 JAR 包的啟動(dòng)、停止和日志管理,需要的朋友可以參考下
    2024-09-09
  • JavaMail整合Spring實(shí)現(xiàn)郵件發(fā)送功能

    JavaMail整合Spring實(shí)現(xiàn)郵件發(fā)送功能

    這篇文章主要為大家詳細(xì)介紹了JavaMail整合Spring實(shí)現(xiàn)郵件發(fā)送功能,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2022-08-08
  • SpringBoot項(xiàng)目中連接Gauss數(shù)據(jù)庫(kù)

    SpringBoot項(xiàng)目中連接Gauss數(shù)據(jù)庫(kù)

    本文主要介紹了SpringBoot項(xiàng)目中連接Gauss數(shù)據(jù)庫(kù),文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧
    2024-06-06
  • 如何解決@value獲取不到y(tǒng)aml數(shù)組的問(wèn)題

    如何解決@value獲取不到y(tǒng)aml數(shù)組的問(wèn)題

    文章介紹了在使用YAML配置文件時(shí),通過(guò)@Value注解獲取整數(shù)和數(shù)組列表的配置方法,并提供了兩種解決方案:一種適用于非嵌套列表,另一種適用于嵌套列表等復(fù)雜配置
    2024-11-11
  • 基于Java在netty中實(shí)現(xiàn)線程和CPU綁定

    基于Java在netty中實(shí)現(xiàn)線程和CPU綁定

    這篇文章主要介紹了基于Java在netty中實(shí)現(xiàn)線程和CPU綁定,文章圍繞主題的相關(guān)內(nèi)容展開(kāi)詳細(xì)介紹,具有一定的參考價(jià)值,需要的小伙伴可以參考一下
    2022-05-05
  • JAVA利用泛型返回類型不同的對(duì)象方法

    JAVA利用泛型返回類型不同的對(duì)象方法

    下面小編就為大家?guī)?lái)一篇JAVA利用泛型返回類型不同的對(duì)象方法。小編覺(jué)得挺不錯(cuò)的,現(xiàn)在就分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧
    2017-02-02
  • java中歸并排序和Master公式詳解

    java中歸并排序和Master公式詳解

    大家好,本篇文章主要講的是java中歸并排序和Master公式詳解,感興趣的同學(xué)趕快來(lái)看一看吧,對(duì)你有幫助的話記得收藏一下,方便下次瀏覽
    2022-01-01
  • java原裝代碼完成pdf在線預(yù)覽和pdf打印及下載

    java原裝代碼完成pdf在線預(yù)覽和pdf打印及下載

    本文主要介紹了java原裝代碼完成pdf在線預(yù)覽和pdf打印及下載的方法,具有一定的參考價(jià)值,下面跟著小編一起來(lái)看下吧
    2017-02-02
  • Java 圖片與byte數(shù)組互相轉(zhuǎn)換實(shí)例

    Java 圖片與byte數(shù)組互相轉(zhuǎn)換實(shí)例

    下面小編就為大家?guī)?lái)一篇Java 圖片與byte數(shù)組互相轉(zhuǎn)換實(shí)例。小編覺(jué)得挺不錯(cuò)的,現(xiàn)在就分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧
    2017-02-02
  • 最新評(píng)論