2

次のように設定された Maven プロジェクトがあります。

\src
   \--main
      \--java
         \--fu
            \--bar
               \--AppMain.java
      \--resources
         \--log4j.xml

を使用して pom を使用して、次のmaven-resources-pluginようにリソース ファイルをターゲット ディレクトリに移動します。

        <plugin>
            <artifactId>maven-resources-plugin</artifactId>
            <executions>
                <execution>
                    <id>copy-resources</id>
                    <phase>validate</phase>
                    <goals>
                        <goal>copy-resources</goal>
                    </goals>
                    <configuration>
                        <outputDirectory>my/target/dir/config</outputDirectory>
                        <resources>
                            <resource>
                                <directory>src/main/resources</directory>
                                <filtering>true</filtering>
                            </resource>
                        </resources>
                    </configuration>
                </execution>
            </executions>
        </plugin>

そして、次のmaven-jar-pluginように jar を作成します。

        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-jar-plugin</artifactId>
            <configuration>
                <archive>
                    <manifest>
                        <addClasspath>true</addClasspath>
                        <classpathPrefix>lib/</classpathPrefix>
                        <mainClass>fu.bar.AppMain</mainClass>
                    </manifest>
                </archive>
            </configuration>
        </plugin>

を実行するmvn clean installと、ターゲットの場所にコンパイル済みの jar と\config\log4j.xml. ただし、jar にはlog4j.xml.

log4j.xml を jar から除外して、.xml に移動するにはどうすればよい\my\target\dir\configですか?

4

1 に答える 1

1

これを私のpomに追加するのがコツでした:

<build>
    <resources>
        <resource>
            <directory>src/main/java</directory>
            <includes>
                <include>**/*</include>
            </includes>
            <excludes>
                <exclude>**/*.java</exclude>
            </excludes>
        </resource>
    </resources>
</build>
于 2016-09-26T15:40:36.607 に答える