2010-12-22 11 views
6

Mavenアセンブリプラグイン(バージョン2.2-beta-5)を使用している場合、アセンブルされたjarには、同じパスがある場合にアセンブルされるプロジェクトではなく、依存関係のリソースが含まれているようです。具体的には、私はプロジェクトのlog4j設定ファイルを依存関係から使うのではなく、どのように使うかを考えようとしています。 Project1の依存関係を持っている場合Mavenアセンブリプラグインとリソース

Project1の

-src

--main

---資源

----のlog4j.xml

- それを呼び出しますProject2 - src/main/resourcesにlog4j.xmlファイルもあります。アセンブリプラグインを実行した後、アセンブルされたjarにProject1の代わりにProject2のlog4j.xmlファイルが含まれています。これは、すべての依存ファイルが最初に解凍されているため、最上位のプロジェクトを解凍しようとするとlog4j.xmlファイルがすでに存在しているため上書きされないためです。

アセンブリプラグインが、依存関係の代わりにプロジェクトのファイルを使用するかどうかを確認しますか?

+0

それに関連する詳細の質問:[Custom maven assembly](http://stackoverflow.com/q/3493381/320399) – blong

答えて

1

1つの可能性は、関連ファイルをアセンブリ作成から明示的に除外することです。

<assembly> 
    <id>without-log4j-config</id> 
    <formats> 
     <format>jar</format> 
    </formats> 
    <includeBaseDirectory>false</includeBaseDirectory> 
    <dependencySets> 
     <dependencySet> 
      <unpack>true</unpack> 
      <scope>runtime</scope> 
      <unpackOptions> 
       <excludes> 
        <exclude>**/log4j.xml</exclude> 
        <exclude>**/log4j.properties</exclude> 
       </excludes> 
      </unpackOptions> 
     </dependencySet> 
    </dependencySets> 
    <files> 
     <file> 
      <source>pom.xml</source> 
      <outputDirectory>/</outputDirectory> 
     </file> 
    </files> 
    <fileSets> 
     <fileSet> 
      <useDefaultExcludes>false</useDefaultExcludes> 
      <outputDirectory>/</outputDirectory> 
     </fileSet> 
     <fileSet> 
      <directory>src/main/java</directory> 
      <outputDirectory>/</outputDirectory> 
     </fileSet> 
     <fileSet> 
      <directory>src/main/resources</directory> 
      <outputDirectory>/</outputDirectory> 
     </fileSet> 
    </fileSets> 
    <moduleSets> 
     <moduleSet> 
      <includeSubModules>false</includeSubModules> 
      <sources> 
       <outputDirectoryMapping>/</outputDirectoryMapping> 
       <excludeSubModuleDirectories>false</excludeSubModuleDirectories> 
       <fileSets> 
        <fileSet> 
         <directory>src/main/java</directory> 
         <outputDirectory>/</outputDirectory> 
        </fileSet> 
        <fileSet> 
         <directory>src/main/resources</directory> 
         <outputDirectory>/</outputDirectory> 
        </fileSet> 
       </fileSets> 
      </sources> 
      <binaries> 
       <dependencySets> 
        <dependencySet> 
         <unpack>true</unpack> 
        </dependencySet> 
       </dependencySets> 
      </binaries> 
     </moduleSet> 
    </moduleSets> 
</assembly> 

そして、あなたはあなたのポンポンでこれを必要があります:このような

<dependencySet> 
     <outputDirectory>/</outputDirectory> 
     <includes> 
      <include>${project.groupId}:Project2</include> 
     </includes> 
     <unpack>true</unpack> 
     <unpackOptions> 
      <excludes> 
       <exclude>**/log4j.xml</exclude> 
      </excludes> 
     </unpackOptions> 
    </dependencySet> 
+1

これはアセンブリに正しく入っていますか?それに正しいものを持つ1つのMaven POMファイルを持つことはできません。 :< – ggb667

3

何か作業をする必要があり

<appendAssemblyId>true</appendAssemblyId> 

 <plugin> 
      <artifactId>maven-assembly-plugin</artifactId> 
      <configuration> 
       <appendAssemblyId>true</appendAssemblyId> 
       <descriptors> 
        <descriptor>src/main/resources/whatever-you-name-the-snippet-above.xml</descriptor> 
       </descriptors> 
      </configuration> 
     </plugin> 

これは重要な部分でありますそれがなければ、実行する場合mvn assembly:assemblyカスタムアセンブリが上書きされます。

関連する問題