2

I am having great trouble getting log4j to work with my little maven project. Running the program in Eclipse yields no errors, and the logging works perfectly. However, when I package the project into a jar, I get the following warning:

log4j:WARN No appenders could be found for logger (org.openrdf.sail.memory.MemoryStore).
log4j:WARN Please initialize the log4j system properly.
log4j:WARN See http://logging.apache.org/log4j/1.2/faq.html#noconfig for more info.

The log4j.properties file is packaged into my jar and it resides in src/main/resources for the project. I read this post and the configuration part of the log4j website, but can't figure it out. I have uploaded my POM here. I am thankful for any hint that may help me with my problem.

2
  • Have you checked the contents of your jar if it contains the log4j.property file?
    – khmarbaise
    Jun 24, 2012 at 12:48
  • Please, show us the directory structure of your sources, the directory structure in the jar and the pom.xml.
    – carlspring
    Jul 10, 2013 at 11:19

4 Answers 4

1

Add <resource> tag under the <build></build> tag. By doing this we say takes resources from the specified path if it is not taken default build.

<resources>
    <resource>
        <directory>src/main/resources</directory>
    </resource>
</resources>    
1
  • I disagree. This is the default location from where Maven will try to copy resources (if the directory exists), even you haven't specified it. Defining this is not mandatory, unless you have to use several locations for your resources. You can normally skip this. This is also true for <testResources/>.
    – carlspring
    Jul 10, 2013 at 11:34
1

As warning message says, it can't find appender for logger org.openrdf.sail.memory.MemoryStore. So, ensure you really have log4j.properties file in src/main/resources and then ensure it's packaged into jar as you suppose. Maybe for some reason, I really can't see, it's not packaged. You know, shit sometimes happen... If have such file in a jar, ensure at the end than you configured appender that handle org.openrdf.sail.memory.MemoryStore logger.

Probably the simplest way of checking if this log4j configuration works is to set default console appender for log4j.rootLogger. Do it and write what's going on there.

0

You seems to assemble your jar with it's dependencies. This may cause problems if those jars also contain log4j.properties, and were picked up while over-riding yours. So, it can't find a logger for the class org.openrdf.sail.memory.MemoryStore.

It's to use only one logger file which contain the logging info for your jar, and all the dependencies. It's just a matter of copy and paste. It gives the ability to control the logging level for dependency classes as well.

0

please note that log4j.properties is case-sentive;

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.