1

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

Seth De
  • 417
  • 6
  • 18
  • possible duplicate of [Traditional Open Source Java Application](http://stackoverflow.com/questions/7056080/traditional-open-source-java-application) –  Dec 16 '14 at 04:37
  • Make sure you read the [accepted answer](http://stackoverflow.com/a/7056230/289086) to that suggested duplicate and follow the link to [Introduction to the Standard Directory Layout](http://maven.apache.org/guides/introduction/introduction-to-the-standard-directory-layout.html) –  Dec 16 '14 at 04:38
  • The answer to the question is [here](http://stackoverflow.com/questions/8897528/problems-to-put-log4-properties-classpath) – abhati Dec 16 '14 at 04:56

1 Answers1

1

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.

Benjamin Marwell
  • 1,173
  • 1
  • 13
  • 36