Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Where should log4j.properties be located when using Maven Exec Plugin?

I am trying to use log4j in a project I am executing with the exec-maven-plugin. I have tried placing the file in the following locations:

$PROJECT_HOME
$PROJECT_HOME/src/main/resources
$PROJECT_HOME/target
$PROJECT_HOME/target/classes

For all locations of the file, I am getting the following message when executing the code:

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

Where should the log4j.properties file be located?


exec-maven-plugin config:

...
<plugin>
    <groupId>org.codehaus.mojo</groupId>
    <artifactId>exec-maven-plugin</artifactId>
    <version>1.2</version>
    <configuration>
        <mainClass>mypackage.Main</mainClass>
    </configuration>
</plugin>
...
like image 662
Armand Avatar asked Sep 27 '11 08:09

Armand


People also ask

Where should I place log4j properties file?

The file is named log4j. properties and is located in the $DGRAPH_HOME/dgraph-hdfs-agent/lib directory. The file defines the ROLLINGFILE appenders for the root logger and also sets the log level for the file. The level of the root logger is defined as INFO and attaches the ROLLINGFILE appender to it.


1 Answers

You have two choices:

  1. Put the property file under

./src/main/resources/log4j.xml

  1. You can specify it from the command line:

$ mvn compile exec:java -Dexec.classpathScope=compile -Dexec.mainClass=com.lei.java.sample.Test -Dlog4j.configuration=file:./log4j.xml

like image 114
stones333 Avatar answered Sep 29 '22 16:09

stones333