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).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...
log4j:WARN Please initialize the log4j system properly.
- 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.)
- In the tree view on the left, select the Configuration you'd like to run with logging enabled.
- Click on the Classpath tab along the top.
- Click on the User Entries item in the tree view to select it.
- Click the Advanced... button.
- Select the Add Classpath Variables radio button, and click OK.
- 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.
- 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
TrackBacks[0]
Comments[9]
Posted by lee on July 22, 2004 6:42:04 PM EDT
Reply |
Permalink
Re: Locating log4j.properties within Eclipse
Thank You !!!!
This has been driving my nuts for 3 days...
Comment from Anonymous on March 7, 2005 6:04:11 PM EST
When I add LOG4J_PROPS, the error message about no appenders goes away, but there is an unwelcome side effect.
<pre>
Prior to the change, Run... [Test] displays
(*) Run a single test
Project foo
Test class: com.foo.test.Test
Test method:testBar
</pre>
After adding LOG4J_PROPS, the test method goes away. It's not a writeable text-entry field, so I cannot retype the desired method. This causes all tests in the class to run, not just the desired method. Ideas?
<p>
Also, is there a way to have one LOG4J_PROPS apply as a default to all tests?
Comment from Monte on March 9, 2005 2:47:02 PM EST
How about creating a jar file, say log4jprops.jar, that contains only log4j.properties?<br>
<br>Then add log4jprops.jar to your project build path the same way you added log4j.jar
Comment from 13miles on May 12, 2005 3:03:32 AM EDT
It looks like it's not working with log4j.xml because I keep having the same message.
D.
Comment from Anonymous on June 24, 2005 9:49:12 AM EDT
It looks like it's not working with log4j.xml because I keep having the same message.
D.
Comment from Anonymous on June 24, 2005 9:49:16 AM EDT
hey dudes. I also had a great problem configuring log4j. I tried creating a jar file with log4j.properties and this works briliantly. Biggest advantage is that the jar file is added 'relatively' to the workspace so that i can easily share my project with other developers.
Comment from Martin on July 21, 2005 7:41:38 AM EDT
This does not seem to work if you are using log4j in conjunction with Commons logging...
Comment from Anonymous on July 21, 2005 4:12:47 PM EDT
i don't know what commons logging is for, but my build is definitely using the file 'commons-logging-1.0.4.jar' for something.
To test this i renamed it and i ended up with no reporting into the console window in Eclipse 3.1. So i would say i am running it with commons logging of some kind.
Comment from Martin on July 22, 2005 4:55:57 AM EDT
Hi,
the solution specified by you might work for java projects, but how do i achieve the same in plugin projects. I am using Eclipse and use RCP plugin architecture.
There is no classpath as suggested by you in the debug/run configuration for plugin projects.
tia
-mohit
Comment from Mohit on October 26, 2005 7:57:24 AM EDT
TrackBack to http://www.leegrey.com/hmm/addTrackBack.action?entry=1090536124000