不从Maven构建中排除Log4j文件

时间:2017-02-24 22:59:34

标签: java maven

我在src / main / resources中有一个log4j.xml文件,我试图从jar文件中排除。我在父pom文件中有一个3.0.0版本的属性。

...
       <build>
            <plugins>
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-jar-plugin</artifactId>
                    <version>${maven-jar-plugin.version}</version>
                    <configuration>
                        <excludes>
                            <exclude>**/log4j.xml</exclude>
                        </excludes>
                    </configuration>
                </plugin>
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-resources-plugin</artifactId>
                    <version>${maven-resources-plugin.version}</version>
                    <configuration>
                        <!-- specify UTF-8, ISO-8859-1 or any other file encoding -->
                        <encoding>UTF-8</encoding>
                    </configuration>
                </plugin>
...

3 个答案:

答案 0 :(得分:0)

我升级到maven-jar-plugin的3.0.0版本,并将排除更改为“src / main / resources / log4j.xml”中的“** / log4j.xml”,我暂时切换了它,所以我不确定是否需要一个修复器。

答案 1 :(得分:0)

如果你使用<exclude>**/*log4j*</exclude>如果你可以接受这种模式,它应该有用。

请注意文档底部的内容:https://maven.apache.org/plugins/maven-jar-plugin/examples/include-exclude.html

请注意,模式需要相对于为插件的classesDirectory参数指定的路径。

答案 2 :(得分:0)

根据maven手册(https://maven.apache.org/plugins/maven-resources-plugin/examples/include-exclude.html),您必须将文件包含在resources部分中。因此,如果文件位于src / resources上,则配置为:

<project>
...
<name>My Resources Plugin Practice Project</name>
...
<build>
  ...
  <resources>
    <resource>
      <directory>src/resources</directory>
      <excludes>
        <exclude>**/log4j.xml</exclude>
      </excludes>
    </resource>
    ...
  </resources>
...
</build>
...
</project>

希望有所帮助。