I have a
src/main/resources/log4j.xml
file which I would like to be included in the jar when I perform a mvn assembly:assembly
but excluded when I perform a mvn package
. How could I do this?
I have read several maven docs and questions here but I've been unable so far to do this. I tried many approaches, all of them failed.
Basically, I have in the <build><plugins>
section of my pom:
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<configuration>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
</configuration>
</plugin>
and then in the <build>
section
<resources>
<resource>
<directory>src/main/resources</directory>
<excludes>
<exclude>src/main/resources/log4j.xml</exclude>
</excludes>
</resource>
</resources>
but I get log4j.xml included everywhere.
Anything you place in the <exclude>
or <include>
elements is treated as relative to the <directory>
specified. So, they way you have it currently, Maven will try to exclude resource ${basedir}/src/main/resources/src/main/resources/log4j.xml
which probably does not exist. Try setting the resources element like this:
<resources>
<resource>
<directory>src/main/resources</directory>
<excludes>
<exclude>**/log4j.xml</exclude>
</excludes>
</resource>
As a side note, the assembly:assembly
goal is deprecated. Per the maven-assembly-plugin docs , use the single
goal instead.
org.apache.maven.plugins
works fine, simple control over including or excluding files in package phase!
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>3.0.2</version>
<configuration>
<excludes>
<exclude>**/password.properties</exclude>
</excludes>
</configuration>
</plugin>
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.