6

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

プロジェクト1

-src

- 主要

- -資力

----log4j.xml

Project1 に依存関係 (Project2 と呼びます) がある場合、src/main/resources に log4j.xml ファイルもあり、アセンブリ プラグインを実行した後、アセンブルされた jar には、Project1 の代わりに Project2 の log4j.xml ファイルが含まれます。これは、すべての依存関係が最初にアンパックされているためであると考えられます。そのため、最上位プロジェクトをアンパックしようとすると、log4j.xml ファイルが既に存在し、上書きされません。

アセンブリ プラグインが依存関係のファイルではなくプロジェクトのファイルを使用するようにする方法はありますか?

4

2 に答える 2

2

このようなものが動作するはずです:

<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>

そして、あなたはあなたのpomでこれを必要とするでしょう:

        <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>

これは重要な部分です:

<appendAssemblyId>true</appendAssemblyId>

これがないと、mvn assembly:assemblyカスタム アセンブリを実行すると上書きされます。

于 2010-12-28T02:09:35.753 に答える
1

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

    <dependencySet>
        <outputDirectory>/</outputDirectory>
        <includes>
            <include>${project.groupId}:Project2</include>
        </includes>
        <unpack>true</unpack>
        <unpackOptions>
            <excludes>
                <exclude>**/log4j.xml</exclude>
            </excludes>
        </unpackOptions>
    </dependencySet>
于 2010-12-23T02:20:30.200 に答える