我有一个maven项目设置如下:
src
--main
--java
--fu
--bar
--AppMain.java
--resources
--log4j.xml
使用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和configlog4j.xml
。但是,jar还包含log4j.xml
。
如何从jar中排除log4j.xml并仍将其移动到mytargetdirconfig
?
把这个添加到我的pom是一个技巧:
<build>
<resources>
<resource>
<directory>src/main/java</directory>
<includes>
<include>**/*</include>
</includes>
<excludes>
<exclude>**/*.java</exclude>
</excludes>
</resource>
</resources>
</build>