I will find out that the location of the log4j.properties file depends on the type of Eclipse project.
In particular, for the Eclipse dynamic web project, most of the answers related to adding log4j.properties to the military file do not actually add the properties file to the right place, especially for Tomcat / Apache.
Here are some of my research and my solution to the problem (again specifically for a dynamic web project running on Tomcat / Apache 6.0)
See this article on how Tomcat will load classes. It is different from the usual class loader for Java. ( https://www.mulesoft.com/tcat/tomcat-classpath ) Note that it only looks in two places in the war file, WEB-INF / classes and WEB-INF / lib.
Please note that using Dynamic Web Project it is not practical to store your .properties file in the build /../ classes directory, since this directory is cleaned up every time you clean up your project.
Tomcat does not process .property files in the WEB-INF / lib location.
You cannot save the log4j.properties file in the src directory, as Eclipse abstracts this directory from your view.
The only way I found to solve this problem is to change the assembly and add an additional directory, which will eventually load into the WEB-INF / classes directory in the war file. In particular....
(1) Right-click your project in the project explorer, select "Create" → "Folder". You can name the folder anything you like, but the standard in this case is "resources." A new folder should appear at the root level of your project.
(2) Move the log4j.properties file to this new folder.
(3) Right-click the project again and select Build Path → Configure Build Path. Select the Sources tab. Click the "Add Folder" button. Find your new folder created in step (1) above. Select "OK."
(4) Back to the eclipse Project Explorer Project view, note that the folder has now been moved to the Java Resources area (i.e., it is no longer in the root due to the abstraction of the eclipse presentation).
(5) Clean your project.
(6) To verify that the .properties file exists in WEB-INF / classes in your war file, export the war file to a convenient location (right-click Project → Export → War file) and check the contents. Note that the log4j file .properties is now displayed in WEB-INF / classes.
(7) Contribute to the Tomcat / Apache project and note that log4j now works.
Now that log4j is working, start logging in, solve the problems of the world, take your free time and enjoy a delicious adult drink.
Robert Bender Apr 10 '14 at 22:01 2014-04-10 22:01
source share