public static void main(String[] args) throws Exception { Configuration conf = new Configuration(); conf.set("mapred.job.tracker", "localhost:8021"); conf.set("fs.default.name", "hdfs://localhost:8020"); // String[] ars = new String[]{"/user/zhwang1988/input01/sample.txt", // "/user/zhwang1988/newout01"}; // String[] otherArgs = new GenericOptionsParser(conf, ars).getRemainingArgs(); // if (otherArgs.length != 2) { // System.err.println("Usage: wordcount <in> <out>"); // System.exit(2); // } Job job = new Job(conf, "Max temperature"); File jarFile = EJob.createTempJar("bin"); EJob.addClasspath("/Users/zhwang1988/desktop/hadoop-1.2.1/conf"); ClassLoader classLoader = EJob.getClassLoader(); Thread.currentThread().setContextClassLoader(classLoader); job.setJarByClass(WordCount.class); ((JobConf) job.getConfiguration()).setJar(jarFile.toString()); job.setNumReduceTasks(2); // job.setMapperClass(MaxTemperatureMapper.class); job.setReducerClass(MapTemperatureReducer.class); job.setOutputKeyClass(Text.class); job.setOutputValueClass(IntWritable.class); FileInputFormat.addInputPath( job, new Path("hdfs://localhost:8020/user/zhwang1988/input01/1901")); FileOutputFormat.setOutputPath(job, new Path("hdfs://localhost:8020/user/zhwang1988/output02")); System.exit(job.waitForCompletion(true) ? 0 : 1); }
public static void main(String[] args) throws Exception { // Add these statements. XXX File jarFile = EJob.createTempJar("bin"); EJob.addClasspath("/home/hadoop/hadoop-1.0.0/conf"); ClassLoader classLoader = EJob.getClassLoader(); Thread.currentThread().setContextClassLoader(classLoader); Configuration conf = new Configuration(); conf.set("mapred.job.tracker", "192.168.192.100:9001"); // String[] ars=new String[]{"input","newout"}; String[] ars = new String[] { "hdfs://192.168.192.100:9000/user/root/input_cents", "hdfs://192.168.192.100:9000/user/root/output_cents" }; String[] otherArgs = new GenericOptionsParser(conf, ars).getRemainingArgs(); if (otherArgs.length != 2) { System.err.println("Usage: wordcount <in> <out>"); System.exit(2); } conf.set("DICTPATH", DICT_PATH); Job job = new Job(conf, "word count"); // 新建MapReduce作业 // And add this statement. XXX ((JobConf) job.getConfiguration()).setJar(jarFile.toString()); job.setJarByClass(GenCents.class); // 设置作业启动类 job.setMapperClass(TokenizerMapper.class); job.setCombinerClass(IntSumReducer.class); job.setReducerClass(IntSumReducer.class); job.setOutputKeyClass(Text.class); job.setOutputValueClass(Text.class); FileInputFormat.addInputPath(job, new Path(otherArgs[0])); FileOutputFormat.setOutputPath(job, new Path(otherArgs[1])); System.exit(job.waitForCompletion(true) ? 0 : 1); }