2016-09-06 16 views
-1

modulesプロジェクト。Maven - jarファイルを圧縮する簡単なプラグイン

-1 
    -pom.xml 
-2 
    -pom.xml 
-3 
    -pom.xml 
-parent 
    -pom.xml 

であり、すべてのモジュールが親のpomによって継承されます。私は親のポンポンを編集しているかしていると私は2瓶(-1から-2)

とジッパーを構築するためのプラグインを作成したい私はその

<plugin> 
      <groupId>org.apache.maven.plugins</groupId> 
      <artifactId>maven-antrun-plugin</artifactId> 
      <version>1.7</version> 
      <executions> 
       <execution> <id>createDistJar</id> 
        <goals> <goal>run</goal> </goals> <phase>package</phase> 
        <configuration> 
         <target> 
          <echo message="${project.build.directory}"/> 
          <mkdir dir="${project.build.directory}"/> 
          <zip destfile="${project.build.directory}/JawaBot-${project.version}-dist.zip" 
           basedir="target/" includes="JawaBot-${project.version}-dist-rh/**"> 
          </zip> 
         </target> 
        </configuration> 
       </execution> 
      </executions> 
     </plugin> 
     <plugin> 
      <groupId>org.codehaus.mojo</groupId> 
      <artifactId>build-helper-maven-plugin</artifactId> 
      <version>1.8</version> 
      <executions> 
       <execution> 
        <id>uploadDistJar</id> <goals> <goal>attach-artifact</goal> </goals> 
        <phase>package</phase> 
        <configuration> 
         <artifacts> 
          <artifact> 
           <file>${project.build.directory}/JawaBot-${project.version}-dist.zip</file> 
           <type>zip</type> 
          </artifact> 
         </artifacts> 
        </configuration> 
       </execution> 
      </executions> 
     </plugin> 

のようなものを試してみましたが、それはzipファイルをcretesすべての/より大きなフォルダ内のすべてのモジュールに対して。

+1

[Mavenアセンブリプラグイン] (http://maven.apache.org/plugins/maven-assembly-plugin/)が問題の解決策になるかもしれません。 – superbob

+0

私は例を教えてくれますか? –

+0

khmarbaiseは私より速かった。彼の答えは良いです。 – superbob

答えて

1

ディストリビューションに含めるモジュールの依存関係を含む補足のpomファイルで別のモジュール(xyz-dist)を作成します。

次のようなあなたの親のポンポンでDISTモジュールを追加します:distモジュールで

<modules> 
     <module>dist</module> 
     <module>package-1</module> 
     <module>package-2</module> 
    </modules> 

あなたのPOMに次の行を追加します。

<project...> 

    <parent> 
    </parent> 

    <packaging>pom</packaging> 

    <dependencies> 
     Dependencies of the modules you would like to package 
    </dependencies> 

<build> 
    <plugins> 
     <plugin> 
      <artifactId>maven-assembly-plugin</artifactId> 
      <executions> 
       <execution> 
        <id>make-bundles</id> 
        <phase>package</phase> 
        <goals> 
         <goal>single</goal> 
        </goals> 
        <configuration> 
         <descriptors> 
          <descriptor>src/assembly/dist.xml</descriptor> 
         </descriptors> 
        </configuration> 
       </execution> 
      </executions> 
     </plugin> 
    </plugins> 
</build> 

dist.xmlは以下が含まれている必要があります。

<assembly xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.0" 
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.0 http://maven.apache.org/xsd/assembly-1.1.0.xsd"> 

    <id>dist</id> 

    <formats> 
     <format>zip</format> 
    </formats> 

    <includeBaseDirectory>false</includeBaseDirectory> 

    <dependencySets> 
     <dependencySet> 
      <outputDirectory>/</outputDirectory> 
      <useProjectArtifact>false</useProjectArtifact> 
      <unpack>false</unpack> 
      <scope>runtime</scope> 
     </dependencySet> 
    </dependencySets> 
</assembly> 
+0

私は親のpom.xmlにモジュールを追加する必要がありますか?私はすべてのモジュールを私はzipで収集したいプラグインmaven-assembly-pluginを追加し、私の親フォルダにdist.xmlを作成しますか? –

+0

モジュールの依存関係をdist pomに追加するだけです。それは... distモジュールにmaven-assembly-pluginを追加します。 – khmarbaise

+0

これで、zipを作成しますが、.jarファイルはありません私の1,2モジュールですが、すべてのdepencances –

関連する問題