之前运行hadoop的方式是首先编写好程序,然后再将程序打包成jar包,然后上传到服务器中运行。
现在的有一种方法是通过在本地idea中可以将jar包提交到远程集群中运行。
简单的代码
一个简单的例子:
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.FileSystem;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.io.IntWritable;
import org.apache.hadoop.io.LongWritable;
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;
import java.io.IOException;
import java.net.URI;
public class WordCount {
public static class WordCountMapper extends Mapper<LongWritable, Text, Text, IntWritable>{
private final static IntWritable result = new IntWritable(1);
private final static Text Key = new Text();
@Override
protected void map(LongWritable key, Text value, Context context) throws IOException, InterruptedException {
// super.map(key, value, context);
String line = value.toString();
String[] words = line.split(" ");
for(String word: words){
Key.set(word);
context.write(Key, result);
}
}
}
public static class WordCountReduce extends Reducer<Text, IntWritable, Text, IntWritable