hadoop上运行java程序
来源:互联网 发布:广州梦享网络 编辑:程序博客网 时间:2024/06/02 09:40
转自:http://blog.sina.com.cn/s/blog_5d2184eb0100r0tz.html
建立WordCount.java文件
package org.myorg;
import java.io.IOException;
import java.util.*;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.conf.*;
import org.apache.hadoop.io.*;
import org.apache.hadoop.mapred.*;
import org.apache.hadoop.util.*;
public class WordCount {
public static class Map extends MapReduceBase implements Mapper<LongWritable, Text, Text, IntWritable> {
private final static IntWritable one = new IntWritable(1);
private Text word = new Text();
public void map(LongWritable key, Text value, OutputCollector<Text, IntWritable> output, Reporter reporter) throws IOException {
String line = value.toString();
StringTokenizer tokenizer = new StringTokenizer(line);
while (tokenizer.hasMoreTokens()) {
word.set(tokenizer.nextToken());
output.collect(word, one);
}
}
}
public static class Reduce extends MapReduceBase implements Reducer<Text, IntWritable, Text, IntWritable> {
public void reduce(Text key, Iterator<IntWritable> values, OutputCollector<Text, IntWritable> output, Reporter reporter) throws IOException {
int sum = 0;
while (values.hasNext()) {
sum += values.next().get();
}
output.collect(key, new IntWritable(sum));
}
}
public static void main(String[] args) throws Exception {
JobConf conf = new JobConf(WordCount.class);
conf.setJobName("wordcount");
conf.setOutputKeyClass(Text.class);
conf.setOutputValueClass(IntWritable.class);
conf.setMapperClass(Map.class);
conf.setCombinerClass(Reduce.class);
conf.setReducerClass(Reduce.class);
conf.setInputFormat(TextInputFormat.class);
conf.setOutputFormat(TextOutputFormat.class);
FileInputFormat.setInputPaths(conf, new Path(args[0]));
FileOutputFormat.setOutputPath(conf, new Path(args[1]));
JobClient.runJob(conf);
}
}
然后编译WordCount.java文件,把它制作成可执行jar包
javac -d . -classpath /root/hadoop-0.20.1/hadoop-0.20.1-core.jar WordCount.java
然后在org的同级目录上建立manifest.mf
在里面写上Main-Class: org.myorg.WordCount
然后保存并执行jar -cvfm count.jar manifest.mf org/
然后在hdfs上建立一个文件夹,hadoop fs -mkdir /test
hadoop fs -put /root/wordtestnum.txt /test
然后执行hadoop jar /root/Desktop/count.jar /test/in /test/out
查看运行结果hadoop fs -cat /test/out/part-00000
- hadoop上运行java程序
- hadoop 上运行java程序
- hadoop上运行Java程序
- 在hadoop上运行java程序
- 运行hadoop程序、java
- 原生态在hadoop上运行java程序
- linux /hadoop 运行java 程序
- hadoop上运行c++程序步骤
- hadoop上运行c++程序步骤
- 在idea上运行hadoop程序
- linux下eclipse上运行hadoop自带wordcount程序
- HadoopCV(2)—— hadoop平台上运行javaCV程序
- (转)hadoop上运行c++程序步骤
- python版的mapreduce程序运行在hadoop上
- hadoop 3.0.0 上运行pipes c++ 程序
- hadoop上的两种运行mapreduce程序的方法
- 自己写wordcount程序在hadoop上运行
- 在Hadoop上运行python程序错误集合
- 分布式与非分布式java程序比较
- test_and_set_bit
- C# 多线程基础,仅以此心得献给那些渴望学习多线程的朋友
- Centos Oprofile 安装过程的几个错误注意点
- 保持简单----纪念丹尼斯•里奇(Dennis Ritchie)
- hadoop上运行java程序
- SQL Server 2008 R2学习笔记:业务人员账号与权限管理
- 悲观锁和乐观锁
- Excel VBA - Range对象
- MFC数据类型(Data Type)
- 直方图均衡化—matlab实现
- C语言中不能使用引用传参
- C++面向对象的方法
- 全面解析布局(Grid & Canvas &StackPanel &Wrappanel