我正在为我的项目使用maven。当我运行程序时,我收到此错误,因此我无法看到我的程序执行进度,尽管该程序正在产生预期的输出。
srimanth@srimanth-Inspiron-N5110:~/CCHD&CCHA/mangoes$ mvn exec:java -q -Dexec.mainClass=bananas.MapReduceColorCount -Dexec.args="hdfs://localhost:9000/users.avrofile hdfs://localhost:9000/pleaseatleastnow6"
log4j:WARN No appenders could be found for logger (org.apache.hadoop.util.Shell).
log4j:WARN Please initialize the log4j system properly.
log4j:WARN See http://logging.apache.org/log4j/1.2/faq.html#noconfig for more info.
srimanth@srimanth-Inspiron-N5110:~/CCHD&CCHA/mangoes$
这是我的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/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>fruits</groupId>
<artifactId>mangoes</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>Hadoop</name>
<description>Hadoop
Hadoop</description>
<dependencies>
<dependency>
<groupId>org.apache.avro</groupId>
<artifactId>avro</artifactId>
<version>1.7.6</version>
</dependency>
<dependency>
<groupId>org.apache.avro</groupId>
<artifactId>avro-mapred</artifactId>
<version>1.7.6</version>
<classifier>hadoop2</classifier>
</dependency>
<dependency>
<groupId>org.apache.hadoop</groupId>
<artifactId>hadoop-yarn-api</artifactId>
<version>2.6.0</version>
</dependency>
<dependency>
<groupId>org.apache.hadoop</groupId>
<artifactId>hadoop-common</artifactId>
<version>2.6.0</version>
</dependency>
<dependency>
<groupId>org.apache.hadoop</groupId>
<artifactId>hadoop-hdfs</artifactId>
<version>2.6.0</version>
</dependency>
<dependency>
<groupId>org.apache.hadoop</groupId>
<artifactId>hadoop-mapreduce-client-app</artifactId>
<version>2.6.0</version>
</dependency>
<dependency>
<groupId>org.apache.hadoop</groupId>
<artifactId>hadoop-mapreduce-client-common</artifactId>
<version>2.6.0</version>
</dependency>
<dependency>
<groupId>org.apache.hadoop</groupId>
<artifactId>hadoop-yarn-client</artifactId>
<version>2.6.0</version>
</dependency>
<dependency>
<groupId>org.apache.hadoop</groupId>
<artifactId>hadoop-client</artifactId>
<version>2.6.0</version>
</dependency>
<dependency>
<groupId>org.apache.hadoop</groupId>
<artifactId>hadoop-mapreduce-client-core</artifactId>
<version>2.6.0</version>
</dependency>
<dependency>
<groupId>org.apache.hadoop</groupId>
<artifactId>hadoop-yarn-common</artifactId>
<version>2.6.0</version>
</dependency>
</dependencies>
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.3</version>
<configuration>
<source>1.7</source>
<target>1.7</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.avro</groupId>
<artifactId>avro-maven-plugin</artifactId>
<version>1.7.6</version>
<executions>
<execution>
<phase>generate-sources</phase>
<goals>
<goal>schema</goal>
</goals>
<configuration>
<sourceDirectory>${project.basedir}/../</sourceDirectory>
<outputDirectory>${project.basedir}/target/generated-sources/</outputDirectory>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</pluginManagement>
</build>
</project>
我错过了任何依赖吗?如何/在哪里正确配置log4j。提前致谢。我将不胜感激。
答案 0 :(得分:5)
对于Maven,您必须将log4j.properties或log4j.xml文件放在main / resources文件夹中。而已。别无他法。创建自己的属性文件。这样的事情。
log4j.rootLogger=DEBUG, CA
log4j.appender.CA=org.apache.log4j.ConsoleAppender
log4j.appender.CA.layout=org.apache.log4j.PatternLayout
log4j.appender.CA.layout.ConversionPattern=%-4r [%t] %-5p %c %x - %m%n
您可以向log4j.rootlogger属性提供INFO,ERROR,WARNING,FATAL和DEBUG。用适合您需求的日志模式替换调试。
答案 1 :(得分:1)
按照警告中给出的URL。它将给出一些指导性信息。
http://logging.apache.org/log4j/1.2/faq.html#noconfig
来自网站:
当默认配置文件为log4j.properties和时,会发生这种情况 无法找到log4j.xml,应用程序不执行任何显式操作 组态。 log4j使用Thread.getContextClassLoader()。getResource() 找到默认配置文件,不直接检查 文件系统。知道要放置的适当位置 log4j.properties或log4j.xml需要了解搜索 正在使用的类加载器的策略。 log4j不提供默认值 配置,因为输出到控制台或文件系统可能是 在某些环境中禁止使用。
您需要log4j.properties
或log4j.xml
。构建最适合您需求的。阅读Log4J manua l将为您提供一些帮助构建配置文件的知识