将资源文件移动到目标并从 jar 中排除
Move resource files to target and exclude from jar
我有一个这样设置的 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
.
如何从 jar 中排除 log4j.xml 并将其移动到 \my\target\dir\config
?
将这个添加到我的 pom 中是诀窍:
<build>
<resources>
<resource>
<directory>src/main/java</directory>
<includes>
<include>**/*</include>
</includes>
<excludes>
<exclude>**/*.java</exclude>
</excludes>
</resource>
</resources>
</build>
我有一个这样设置的 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
.
如何从 jar 中排除 log4j.xml 并将其移动到 \my\target\dir\config
?
将这个添加到我的 pom 中是诀窍:
<build>
<resources>
<resource>
<directory>src/main/java</directory>
<includes>
<include>**/*</include>
</includes>
<excludes>
<exclude>**/*.java</exclude>
</excludes>
</resource>
</resources>
</build>