2016-08-25 48 views
2

哪些檔案格式可以解壓密碼dependencies:unpack-dependencies?例如,據我看到它不能解包RPM包。有沒有一個它支持的格式列表?是否有一些技巧可以讓Maven解包RPM包?哪些格式可以依賴:unpack-dependencies目標解壓?

+1

也許這裏回答:http://stackoverflow.com/questions/15393110/maven-custom-archive-extension-how-do-i-use-unpack-dependencies –

回答

2

Maven Dependency Plugin使用內部Plexus Archiver來歸檔和取消歸檔文件。截至今日,版本2.10的maven-dependency-plugindepends on version 2.9plexus-archiver

Plexus組件在META-INF/plexus/components.xml文件的幫助下進行配置。在依賴插件的情況下,你可以看到這個文件​​,並宣佈爲取檔以下擴展名:zipjarwarearswcnaresbsarcarparrar。它們全都使用相同的ZipUnArchiver組件,這意味着它們都被解壓縮,就好像它們是ZIP文件一樣。

叢歸檔2.9還附帶了一系列預定義取檔的,並增加了:bzip2gziptartgztar.gztbz2tar.bz2到列表中。最新版本還增加了snappyxz文件。


如果你希望能夠解壓自定義擴展,您將需要創建一個能夠拆開包裝的一個新項目,並將其註冊爲一叢的組成部分。對於RPM軟件包,你可以創建一個rpm-archiver Maven項目,並有內部META-INF/plexus/components.xml如下:

<component-set> 
    <components> 
    <component> 
     <role>org.codehaus.plexus.archiver.UnArchiver</role> 
     <role-hint>rpm</role-hint> 
     <implementation>class.able.to.unpack.rpm.packages</implementation> 
     <instantiation-strategy>per-lookup</instantiation-strategy> 
    </component> 
    </components> 
</component-set> 

其中class.able.to.unpack.rpm.packages是你的自定義類可以解開RPM文件的全名分類。該類必須實現接口org.codehaus.plexus.archiver.UnArchiver,但爲了簡化,您可以使該類繼承自org.codehaus.plexus.archiver.AbstractUnArchiver。所有你需要做的就是覆蓋​​和execute(path, outputDirectory)方法。前者需要將getSourceFile()檢索到的文件抽取到getDestDirectory()檢索的目錄中,而後者僅將源文件中指定的path抽取到給定的outputDirectory中。

編譯和安裝這個新項目後,可以作爲一個依賴它添加到maven-dependency-plugin

<plugin> 
    <artifactId>maven-dependency-plugin</artifactId> 
    <version>2.10</version> 
    <!-- rest of your configuration --> 
    <dependencies> 
     <dependency> 
      <groupId>my.archiver</groupId> 
      <artifactId>rpm-archiver</artifactId> 
      <version>0.0.1</version> 
     </dependency> 
    </dependencies> 
</plugin> 

這樣,當插件運行時,它會知道如何拆開具有rpm擴展名的文件,並將使用您在components.xml中配置的類。