Seth De
Seth De

Reputation: 417

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.

enter image description here

Upvotes: 1

Views: 863

Answers (1)

Benjamin Marwell
Benjamin Marwell

Reputation: 1246

General recommendation

Put it into src/main/resources. You may want to define a more verbose log4j configuration in src/test/resources, if you do use junit tests.

See maven standard directory layout.

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>".

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.

Upvotes: 1

Related Questions