[BlogEntry] Locating log4j.properties within Eclipse


When you try to run a program that does logging from within Eclipse, have you ever seen this:

log4j:WARN No appenders could be found for logger (com.greymatter.MyClass).
log4j:WARN Please initialize the log4j system properly.

This happens because Log4j can't find its .properties file, so it can't configure its appenders, so you don't get any logging information. Here's how to fix this…

  1. In Eclipse, in one of the several places where you can find this, select either Run… or Debug… (Your change will apply to both types of program execution.)
  2. In the tree view on the left, select the Configuration you'd like to run with logging enabled.
  3. Click on the Classpath tab along the top.
  4. Click on the User Entries item in the tree view to select it.
  5. Click the Advanced… button.
  6. Select the Add Classpath Variables radio button, and click OK.
  7. If you see LOG4J_PROPS in the list of variables, select it and click OK. If it is not in the list, click the Configure Variables button. Add a Classpath Variable named LOG4J_PROPS with a value of the absolute path to the folder that contains the log4j.properties file. Once you've completed this process of adding the new variable, you will of course need to select it as you would have done if it had already existed.
  8. Click Apply to save your changes.

That's it! You should now be able to run or debug your app in Eclipse and have log4j configure properly. Ain't life grand?!

Revised January 17, 2005

Leave a Reply

Your email address will not be published. Required fields are marked *

CommentLuv badge