Where is the correct location to put Log4j.properties in an Eclipse project?

后端 未结 10 1623
伪装坚强ぢ
伪装坚强ぢ 2020-11-27 11:19

Where in my Eclipse project should I add the log4j.properties file so that it will work as intended?

10条回答
  •  鱼传尺愫
    2020-11-27 11:59

    Add the log4j.properties file to the runtime class path of the project. Some people add this to the root of the source tree (so that it gets copied to the root of the compiled classes).

    Edit: If your project is a maven project, you can put the log4j.properties in the src/main/resources folder (and the src/test/resources for your unit tests).

    If you have multiple environments (for example development and production), want different logging for each environment, and want to deploy the same jar (or war, or ear) file to each environment (as in one build for all environments) then store the log4j.properties file outside of the jar file and put it in the class path for each environment (configurable by environment). Historically, I would include some known directory in each environment in the classpath and deploy environment specific stuff there. For example, ~tomcat_user/localclasspath where ~tomcat_user is the home directory of the user that will be running the tomcat instance to which my war file will be deployed.

提交回复
热议问题