2015-11-11 14 views
6

私が持っている唯一のMaven体験は他のライブラリを含んでいるので、EclipseでMavenをどのように実現できるかについての非常に基本的な説明が必要です。mavenのzipをjarファイルの隣に追加ファイルをつけて作成する

私は瓶詰めを作成したいと思います。その後、さらに3つのファイルを1つのzipファイルにまとめる必要があります。私のzipの内容は、次のようになります。

A.jar 
B.txt 
C.txt 
D.bat 

私は私pom.xmlファイル内の特定の目標を挿入する必要があります知っています。私は既に類似したトピックに関するStack Overflow(すなわち、here)の記事を見ました。私もhereのようなMavenのドキュメントを試しました。すでにMavenプラグインが必要ですか、それともまだMaven-coreのものですか?

しかし私のスキルはまだ私の場合のためにこの情報を転送するのに十分ではありません。

+1

溶液中でそれらを持っているのはよくないですので、SRC /メイン/リソースにB.TXT、C.txt、D.batを追加などのmaven-アセンブリのプラグインではありません(http://stackoverflow.com/questions/5717183/create-a-zip-with-all-dependencies-with-maven)への回答に記載されています。あなたがしなければならないことは、pom.xmlにmaven-assembly-pluginを組み込み、src/main/assembleにカスタマイズされたassembly.xmlを作成することです。一般に、assembly.xmlのファイルセットは、作成されたアーカイブに何が含まれるかを定義します。mvn clean installを呼び出した後、新しいzipアーカイブがあなたのプロジェクトのターゲットフォルダで利用できるようになります。うまくいくと助かります... –

+0

アセンブリ記述子のデフォルトの場所は 'src/assembly'です。https://maven.apache.org/guides/introduction/introduction-to-the-standard-directory-layoutを参照してください。 html – khmarbaise

答えて

3

カスタムアーティファクトを作成する必要がある場合は、maven-assembly-pluginを使用する必要があります。アセンブリの使用を開始するには、Mavenの本Chapter 8. Maven Assembliesを読んでおくことを強くお勧めします。この章では、Mavenアセンブリの作成について詳細に説明します。読みやすいです。

基本的に、アセンブリはassembly descriptorの助けを借りて作成されます。次のアセンブリ記述子には、プロジェクトメインアーティファクトがzipアーカイブのルートに含まれます。あなたは、その後、あなたは自分のPOMにこのプラグインを宣言する必要があり

<assembly 
    xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.2" 
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
    xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.2 http://maven.apache.org/xsd/assembly-1.1.2.xsd"> 
    <id>assemby-id</id> 
    <formats> 
     <format>zip</format> 
    </formats> 
    <includeBaseDirectory>false</includeBaseDirectory> 
    <files> 
     <file> 
      <source>${project.build.directory}/${project.build.finalName}.${project.packaging}</source> 
      <outputDirectory>/</outputDirectory> 
     </file> 
    </files> 
</assembly> 

(ロジックは同じである)あなたのアーカイブにカスタムファイルを追加するには、ここより <file>または <fileSets>宣言を追加することができます。この場合、プラグインは packageフェーズにバインドされ、上記の記述子で構成されます。デフォルトでは、アセンブリIDはアーカイブの名前に追加されます。ここでそれを削除しました。

<plugin> 
    <artifactId>maven-assembly-plugin</artifactId> 
    <version>2.5.5</version> 
    <executions> 
     <execution> 
      <phase>package</phase> 
      <goals> 
       <goal>single</goal> 
      </goals> 
      <configuration> 
       <descriptors> 
        <descriptor>assembly.xml</descriptor> <!-- path to the descriptor --> 
       </descriptors> 
       <appendAssemblyId>false</appendAssemblyId> 
      </configuration> 
     </execution> 
    </executions> 
</plugin> 

mvn clean packageを実行している場合、あなたはzipアーカイブはtargetディレクトリに作成されていますことがわかります。

+0

$ {project.build.directory}/$ {project.build.finalName}。$ {project.packaging} どの部分に私のファイルを含めるのですか? 、B、C、D? –

+1

@BerndErnst主要な成果物の部分がハードコードされていないように、変数がここにあります。ファイルA〜Dについては、私が答えて言ったように、ファイルごとに ''要素を追加することができます。これはあなたのディレクトリ構造に依存するので、私はより具体的な答えを与えることはできません。 – Tunaki

7
+ project 
    + src/main/java 
    + src/main/resources 
    + src/main/config 
      +B.txt 
      +C.txt 
      +D.bat 
    + src/main/assembly 
      +bin.xml 
    +pom.xml 

bin.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>bin</id> 
    <baseDirectory>/</baseDirectory> 
    <formats> 
    <format>zip</format> 
    </formats> 
    <fileSets> 
    <fileSet> 
     <directory>${project.basedir}/src/main/config</directory> 
     <outputDirectory>/</outputDirectory> 
    </fileSet> 
    <fileSet> 
     <directory>${project.build.directory}</directory> 
     <outputDirectory>/</outputDirectory> 
     <includes> 
     <include>*.jar</include> 
     </includes> 
    </fileSet> 
    </fileSets> 
</assembly> 

poml.xml

<plugin> 
    <artifactId>maven-assembly-plugin</artifactId> 
    <version>2.6</version> 
    <configuration> 
     <descriptors> 
      <descriptor>src/main/assembly/bin.xml</descriptor> 
     </descriptors> 
     <appendAssemblyId>false</appendAssemblyId> 
    </configuration> 
    <executions> 
     <execution> 
      <id>make-assembly</id> <!-- this is used for inheritance merges --> 
      <phase>package</phase> <!-- append to the packaging phase. --> 
      <goals> 
       <goal>single</goal> 
      </goals> 
     </execution> 
    </executions> 
</plugin> 

出力: MVNきれいなパッケージ

+ artifactId-version.zip 
    + B.txt 
    +C.txt 
    +D.txt 
    +artifactId-version.jar 

は、CLASSSPATH

関連する問題