2016-02-12 76 views
1

我想maven將陰影插件創建的超級jar和all_files目錄下的shell腳本合併在一起。maven zip超級jar和shell腳本

項目結構如下所示:

all_files/ 
    mvn_script.sh 
    projB-shaded.jar 

    maven_project/ 
     guide/ 
      parent-pom.xml 
     projA/ 
      pom.xml 
     projB/ 
      pom.xml 

的罐子被項目B的POM文件生成,然後放入outtermost文件夾準備好與shell腳本來拉上。原因是,shell腳本可以調用jar文件來執行該項目。

我希望其他程序員能夠輕鬆解壓縮文件並運行shell腳本而不用擔心。而且我還需要將maven包裝在腳本和jar中。我不確定如何在陰影插件中實現它。

注意:我不想使用assembly-plugin,因爲它沒有打包依賴的jar。

<plugin> 
    <groupId>org.apache.maven.plugins</groupId> 
    <artifactId>maven-shade-plugin</artifactId> 
    <version>2.4.3</version> 
    <executions> 
     <execution> 
     <phase>package</phase> 
     <goals> 
      <goal>shade</goal> 
     </goals> 
     <configuration> 
      <minimizeJar>true</minimizeJar> 
      <outputFile>../../guide/${project.artifactId}-${project.version}-shaded.jar</outputFile> 
      <transformers> 
      <transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer"> 
       <manifestEntries> 
       <Main-Class>projB.classB</Main-Class> 
       </manifestEntries> 
      </transformer> 
      </transformers> 
     </configuration> 
     </execution> 
    </executions> 
    </plugin>      

回答

1

您不想使用maven-assembly-plugin來創建超級罐。但你會想用它來創建該ZIP。

目前,您的maven-shade-plugin綁定到package階段。您可以將該執行轉移到prepare-package階段(因爲它實際上準備了最終包裝)添加了與package階段綁定的maven-assembly-plugin的執行。你的程序集會根據陰影JAR(它將會存在,因爲陰影插件已經被執行)和shell腳本創建一個ZIP。

示例描述符將是以下:

<assembly xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.3" 
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
    xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.3 http://maven.apache.org/xsd/assembly-1.1.3.xsd"> 
    <id>your-id</id> 
    <formats> 
     <format>zip</format> 
    </formats> 
    <files> 
     <file> 
      <source>${project.build.directory}/projB-shaded.jar</source> 
      <outputDirectory>/</outputDirectory> 
     </file> 
     <file> 
      <source>/path/to/mvn_script.sh</source> 
      <outputDirectory>/</outputDirectory> 
     </file> 
    </files> 
</assembly> 

具有以下POM配置:

<plugin> 
    <artifactId>maven-shade-plugin</artifactId> 
    <version>2.4.3</version> 
    <executions> 
     <execution> 
      <phase>prepare-package</phase> 
      <goals> 
       <goal>shade</goal> 
      </goals> 
      <configuration> 
       <!-- current configuration --> 
      </configuration> 
     </execution> 
    </executions> 
</plugin> 
<plugin> 
    <artifactId>maven-assembly-plugin</artifactId> 
    <version>2.6</version> 
    <executions> 
     <execution> 
      <id>assemble</id> 
      <goals> 
       <goal>single</goal> 
      </goals> 
      <phase>package</phase> 
      <configuration> 
       <descriptors> 
        <descriptor>/path/to/assembly.xml</descriptor> 
       </descriptors> 
      </configuration> 
     </execution> 
    </executions> 
</plugin> 

用於組件descritor典型位置是src/assembly下爲每Maven standard directory layout

+0

如何將projB-shaded.jar和mvn_script.sh這兩個文件添加到一個zip文件中? – Abhi

+0

在準備包中運行陰影會導致失敗。它似乎在包中運行,還是有另一種配置允許它運行更早? – puhlen