Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/hadoop/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 这是否正确地使用了Log4j Hadoop?_Java_Hadoop_Log4j - Fatal编程技术网

Java 这是否正确地使用了Log4j Hadoop?

Java 这是否正确地使用了Log4j Hadoop?,java,hadoop,log4j,Java,Hadoop,Log4j,我不断得到以下错误: OpcodeCount.java:24: error: <identifier> expected LOG.warn("something :)"); ^ OpcodeCount.java:24: error: illegal start of type 以下是我的其余代码: import org.apache.log4j.Logger; import java.io.IOException; import java.util.StringTo

我不断得到以下错误:

OpcodeCount.java:24: error: <identifier> expected
LOG.warn("something :)");
        ^
OpcodeCount.java:24: error: illegal start of type
以下是我的其余代码:

import org.apache.log4j.Logger;
import java.io.IOException;
import java.util.StringTokenizer;

import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.io.IntWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Job;
import org.apache.hadoop.mapreduce.Mapper;
import org.apache.hadoop.mapreduce.Reducer;
import org.apache.hadoop.mapreduce.lib.input.FileInputFormat;
import org.apache.hadoop.mapreduce.lib.output.FileOutputFormat;

public class OpcodeCount {

  // debugging output
  private static final Logger LOG = org.apache.log4j.Logger.getLogger(this.getClass());
  LOG.warn("something :)");

  public static class TokenizerMapper extends Mapper<Object, Text, Text, IntWritable>{

    private final static IntWritable one = new IntWritable(1);
    private Text word = new Text();

    // debugging output
    private static final Logger LOG = org.apache.log4j.Logger.getLogger(this.getClass());
    LOG.warn("something :)");

    public void map(Object key, Text value, Context context) throws IOException, InterruptedException {

      StringTokenizer itr = new StringTokenizer(value.toString());
      while (itr.hasMoreTokens()) {
        word.set(itr.nextToken());
        context.write(word, one);
      }
    }
  }

  public static class IntSumReducer extends Reducer<Text,IntWritable,Text,IntWritable> {
    private IntWritable result = new IntWritable();

    // debugging output
    private static final Logger LOG = org.apache.log4j.Logger.getLogger(this.getClass());
    LOG.warn("something :)");

    public void reduce(Text key, Iterable<IntWritable> values, Context context) throws IOException, InterruptedException {
      int sum = 0;
      for (IntWritable val : values) {
        sum += val.get();
      }
      result.set(sum);
      context.write(key, result);
    }
  }

  public static void main(String[] args) throws Exception {
    Configuration conf = new Configuration();
    Job job = Job.getInstance(conf, "opcode count");
    job.setJarByClass(OpcodeCount.class);
    job.setMapperClass(TokenizerMapper.class);
    job.setCombinerClass(IntSumReducer.class);
    job.setReducerClass(IntSumReducer.class);
    job.setOutputKeyClass(Text.class);
    job.setOutputValueClass(IntWritable.class);
    FileInputFormat.addInputPath(job, new Path(args[0]));
    FileOutputFormat.setOutputPath(job, new Path(args[1]));
    System.exit(job.waitForCompletion(true) ? 0 : 1);
  }
}
import org.apache.log4j.Logger;
导入java.io.IOException;
导入java.util.StringTokenizer;
导入org.apache.hadoop.conf.Configuration;
导入org.apache.hadoop.fs.Path;
导入org.apache.hadoop.io.IntWritable;
导入org.apache.hadoop.io.Text;
导入org.apache.hadoop.mapreduce.Job;
导入org.apache.hadoop.mapreduce.Mapper;
导入org.apache.hadoop.mapreduce.Reducer;
导入org.apache.hadoop.mapreduce.lib.input.FileInputFormat;
导入org.apache.hadoop.mapreduce.lib.output.FileOutputFormat;
公共类OpcodeCount{
//调试输出
私有静态最终记录器LOG=org.apache.log4j.Logger.getLogger(this.getClass());
LOG.warn(“某物:)”;
公共静态类TokenizerMapper扩展映射器{
私有最终静态IntWritable one=新的IntWritable(1);
私有文本字=新文本();
//调试输出
私有静态最终记录器LOG=org.apache.log4j.Logger.getLogger(this.getClass());
LOG.warn(“某物:)”;
公共void映射(对象键、文本值、上下文上下文)引发IOException、InterruptedException{
StringTokenizer itr=新的StringTokenizer(value.toString());
而(itr.hasMoreTokens()){
set(itr.nextToken());
上下文。写(单词,一);
}
}
}
公共静态类IntSumReducer扩展了Reducer{
私有IntWritable结果=新的IntWritable();
//调试输出
私有静态最终记录器LOG=org.apache.log4j.Logger.getLogger(this.getClass());
LOG.warn(“某物:)”;
公共void reduce(文本键、Iterable值、上下文上下文)引发IOException、InterruptedException{
整数和=0;
for(可写入值:值){
sum+=val.get();
}
结果集(总和);
编写(键、结果);
}
}
公共静态void main(字符串[]args)引发异常{
Configuration conf=新配置();
Job Job=Job.getInstance(conf,“操作码计数”);
job.setJarByClass(OpcodeCount.class);
setMapperClass(TokenizerMapper.class);
job.setCombinerClass(IntSumReducer.class);
job.setReducerClass(IntSumReducer.class);
job.setOutputKeyClass(Text.class);
job.setOutputValueClass(IntWritable.class);
addInputPath(作业,新路径(args[0]);
setOutputPath(作业,新路径(args[1]);
系统退出(作业等待完成(真)?0:1;
}
}

Log4j不是问题所在,因为是Java编译器抛出了错误

不能在另一个方法或静态初始值设定项块之外调用实例方法


.warn()
移动到
地图()

人-我终于开始工作了-想聊聊天,我会告诉你我是怎么做到的-我的意思是-这真的不适合这么一个问题-但你帮了我这么多-我想和你分享我最终是如何把它放在一起的:)请随意在这里输入。我等会儿再看,伙计-就在你认为你已经脱离险境的时候。。。被这只野兽蒙蔽了双眼你以前处理过那种情况吗?
import org.apache.log4j.Logger;
import java.io.IOException;
import java.util.StringTokenizer;

import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.io.IntWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Job;
import org.apache.hadoop.mapreduce.Mapper;
import org.apache.hadoop.mapreduce.Reducer;
import org.apache.hadoop.mapreduce.lib.input.FileInputFormat;
import org.apache.hadoop.mapreduce.lib.output.FileOutputFormat;

public class OpcodeCount {

  // debugging output
  private static final Logger LOG = org.apache.log4j.Logger.getLogger(this.getClass());
  LOG.warn("something :)");

  public static class TokenizerMapper extends Mapper<Object, Text, Text, IntWritable>{

    private final static IntWritable one = new IntWritable(1);
    private Text word = new Text();

    // debugging output
    private static final Logger LOG = org.apache.log4j.Logger.getLogger(this.getClass());
    LOG.warn("something :)");

    public void map(Object key, Text value, Context context) throws IOException, InterruptedException {

      StringTokenizer itr = new StringTokenizer(value.toString());
      while (itr.hasMoreTokens()) {
        word.set(itr.nextToken());
        context.write(word, one);
      }
    }
  }

  public static class IntSumReducer extends Reducer<Text,IntWritable,Text,IntWritable> {
    private IntWritable result = new IntWritable();

    // debugging output
    private static final Logger LOG = org.apache.log4j.Logger.getLogger(this.getClass());
    LOG.warn("something :)");

    public void reduce(Text key, Iterable<IntWritable> values, Context context) throws IOException, InterruptedException {
      int sum = 0;
      for (IntWritable val : values) {
        sum += val.get();
      }
      result.set(sum);
      context.write(key, result);
    }
  }

  public static void main(String[] args) throws Exception {
    Configuration conf = new Configuration();
    Job job = Job.getInstance(conf, "opcode count");
    job.setJarByClass(OpcodeCount.class);
    job.setMapperClass(TokenizerMapper.class);
    job.setCombinerClass(IntSumReducer.class);
    job.setReducerClass(IntSumReducer.class);
    job.setOutputKeyClass(Text.class);
    job.setOutputValueClass(IntWritable.class);
    FileInputFormat.addInputPath(job, new Path(args[0]));
    FileOutputFormat.setOutputPath(job, new Path(args[1]));
    System.exit(job.waitForCompletion(true) ? 0 : 1);
  }
}