Maven Exclude log4j.properties in Jar file

摘要: This example shows you how to use Maven to exclude the log4j.properties file from your Jar file.

This example shows you how to use Maven to exclude the log4j.properties file from your Jar file.

Note
Please, DO NOT include the log4j.properties into the final Jar file, it will cause multiple log4j.properties files in the classpath, if someone is depending on your Jar, you may accidentally override their logging configurations, depends which Jar is loaded first.
pom.xml
<project>
  <build>
    <plugins>
	<!-- Make this jar executable -->
	<plugin>
		<groupId>org.apache.maven.plugins</groupId>
		<artifactId>maven-jar-plugin</artifactId>
		<configuration>
		        <!-- exclude log4j.properties -->
			<excludes>
				<exclude>**/log4j.properties</exclude>
			</excludes>
			<archive>
			    <manifest>
				<addClasspath>true</addClasspath>
				<mainClass>com.mkyong.core.utils.testing</mainClass>
				<classpathPrefix>dependency-jars/</classpathPrefix>
		            </manifest>
			</archive>
		</configuration>
	</plugin>
    </plugins>
  </build>
</project>

Please pass in your log4j.properties file via log4j.configuration system property like this

$ java -jar -Dlog4j.configuration=file:/full_path/log4j.properties final.jar

上一篇: Create a fat Jar file Maven Assembly Plugin
下一篇: Maven – Create a fat Jar file One-JAR example
 评论 ( What Do You Think )
名称
邮箱
网址
评论
验证
   
 

 


  • 微信公众号

  • 我的微信

站点声明:

1、一号门博客CMS,由Python, MySQL, Nginx, Wsgi 强力驱动

2、部分文章来源于互联网, 若有侵权, 联系邮箱:summer@yihaomen.com, 同时欢迎大家注册用户,主动发布文章.

3、鄂ICP备14001754号-3, 鄂公网安备 42280202422812号