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

后端 未结 10 1537
伪装坚强ぢ
伪装坚强ぢ 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 12:06

    you can add it any where you want, when you run your project, configure the classpath and add the location of the log4j.properties files by clicking on: Run->Run Configuration -> [classpath tab] -> click on user Entries -> Advanced -> Select Add Folder -> select the location of your log4j.properties file

    and then -> OK -> run

    and it should get loaded

    0 讨论(0)
  • 2020-11-27 12:06

    The safest way IMO is to point at the file in your run/debug config

    -Dlog4j.configuration=file:mylogging.properties
    

    ! Be aware: when using the eclipse launch configurations the specification of the file: protocol is mandatory.

    In this way the logger will not catch any logging.properties that come before in the classpath nor the default one in the JDK.

    Also, consider actually use the log4j.xml which has a richer expression syntax and will allow more things (log4j.xml tahe precedence over log4j.properties.

    0 讨论(0)
  • 2020-11-27 12:07

    If you have a library and you want to append the log4j:

    1. Create a folder named "resources" in your projet.
    2. Create a .properties file named log4j
    3. Set properties in log4j.properties file
    4. Push right button in the project and go to properties->Java Build Path and, finally, go to the "Source" tab.
    5. Push Add folder and search the "resources" folder created in step 1.
    6. Finish.

    (I have assumed that you have the log4j library added.)

    PD: Sorry for my english.

    0 讨论(0)
  • 2020-11-27 12:15

    The best way is to create special source folder named resources and use it for all resource including log4j.properties. So, just put it there.

    On the Java Resources folder that was automatically created by the Dynamic Web Project, right click and add a new Source Folder and name it 'resources'. Files here will then be exported to the war file to the classes directory

    0 讨论(0)
提交回复
热议问题