2

我有一个这样的Maven项目:

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

使用 pommaven-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像这样创建罐子:

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

如何从 jar 中排除 log4j.xml 并仍将其移至 jar \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 回答