简体   繁体   中英

log4j.properties cannot be found in classpath

I'm trying to configure my log4j framework by providing a log4j.properties file in my classpath of my plugin, but log4j keeps complaining that it cannot find the file ... Here is a screenshot of my project structure and where I put my log4j.properties file: 在此处输入图片说明

I put the file everywhere I could think of, as shown in the image above, but it still keeps complaining that it cannot find the file. Here is the console output after adding -Dlog4j.debug=true -Dlog4j.configuration=log4j.properties to my VM arguments:

log4j: Trying to find [log4j.properties] using context classloader org.eclipse.core.runtime.internal.adaptor.ContextFinder@6162abf8.
log4j: Trying to find [log4j.properties] using org.eclipse.osgi.internal.baseadaptor.DefaultClassLoader@4caeca49[org.apache.log4j:1.2.16(id=801)] class loader.
log4j: Trying to find [log4j.properties] using ClassLoader.getSystemResource().
log4j: Could not find resource: [log4j.properties].

I'm using eclipse Kepler Service Release 2 and log4j 1.2.15. The plugin is part of a RCP application which is called during the start-up phase of the application to initialize the logging framework. The logging itself works as expected, but I want to adapt a few settings to decrease the logging size. And yes I also added the file to the build-path to ensure that it is also available during execution. Any help or pointers would be appreciated.

Best regards,

Tom

OK I found the solution by myself :) I resolved the problem by explicitly configuring log4j by using the following code:

URL url = getClass().getResource("log4j.properties");        
PropertyConfigurator.configure(url);

Just place your log4j.properties in the package where you call this code and it should work ;) You only have to call this code once when you initialize the log4j framework.

Best regards, Tom

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM