log4j in einfache java-maven-Projekt

Habe ich einfaches java-Projekt. Ich verwalte meine Abhängigkeiten mit maven. Ich fügte hinzu, log4j dependency in meinem pom.xml

Nun will ich nutzen

package com.abc.xyz;

import org.apache.log4j.Logger;

/**
 * Hello world!
 *
 */
public class App 
{
    static final Logger logger = Logger.getLogger(App.class);
    public static void main( String[] args )
    {
        logger.debug("Hello world!");
    }
}

Habe ich meine log4j.Eigenschaften Datei im resources-Ordner.

Wenn ich die App als Java-Anwendung bekomme ich folgenden Fehler.

log4j:WARN No appenders could be found for logger (com.abc.xyz.App).
log4j:WARN Please initialize the log4j system properly.
log4j:WARN See http://logging.apache.org/log4j/1.2/faq.html#noconfig for more info.

So, meine Frage ist wie machen die Laufzeitumgebung weiß, dass meine log4j.Eigenschaften Datei im resources-Ordner.

BEARBEITEN

Hier ist meine pom.xml

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <groupId>com.abc.xyz</groupId>
  <artifactId>learning</artifactId>
  <packaging>jar</packaging>
  <version>1.0-SNAPSHOT</version>
  <name>learning</name>
  <url>http://maven.apache.org</url>
  <dependencies>
  <dependency>
    <groupId>log4j</groupId>
    <artifactId>log4j</artifactId>
    <version>1.2.17</version>
</dependency>
    <dependency>
      <groupId>junit</groupId>
      <artifactId>junit</artifactId>
      <version>4.11</version>
      <scope>test</scope>
    </dependency>
  </dependencies>
  <build>
  <plugins>
    <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-compiler-plugin</artifactId>
        <version>2.3.2</version>
        <configuration>
            <source>1.6</source>
            <target>1.6</target>
        </configuration>
    </plugin>
 </plugins>
 </build>
</project>

und hier ist meine log4j.Eigenschaften Datei

# Define the root logger with appender file
log4j.rootLogger = DEBUG
können wir Ihre pom.xml bitte

InformationsquelleAutor riship89 | 2013-11-12

Schreibe einen Kommentar