简体   繁体   English

打包到jar时配置log4j.properties文件位置

[英]Configure log4j.properties file location when packing to jar

I have a concern that where do we have to put log4j.properties file when packaging to jar file by using maven.what is the best practice here. 我担心使用maven.what打包到jar文件时,在哪里必须将log4j.properties文件放在哪里?这是最佳实践。

在此处输入图片说明

General recommendation 一般建议

Put it into src/main/resources . 将其放入src/main/resources You may want to define a more verbose log4j configuration in src/test/resources , if you do use junit tests. 如果确实使用junit测试,则可能需要在src/test/resources定义更详细的log4j配置。

See maven standard directory layout . 请参阅maven标准目录布局

Setting a new configuration for specific executions 为特定执行设置新配置

If you want to create an executable jar with a main method, you can ship a default configuration in src/main/resources and still provide an overriding log configuration when starting your jvm, using this jvm parameter: -Dlog4j.configuration=file:"<FILE_PATH>" . 如果要使用main方法创建可执行jar,则可以使用以下jvm参数在src/main/resources提供默认配置,并且在启动jvm时仍提供覆盖的日志配置: -Dlog4j.configuration=file:"<FILE_PATH>"

Building for multiple environments 为多种环境构建

You can also create multiple subfolders in your resource configuration and have the maven resource plugin copy the correct log4j.xml to the destination via maven profiles . 您还可以在资源配置中创建多个子文件夹,并使maven资源插件通过maven配置文件将正确的log4j.xml复制到目标。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM