你到8088界面中查看了吗,能不能看到任务信息
很奇怪,没有任何输出信息
你这样执行一下试试,使用hadoop内置的wordcount案例
hadoop jar hadoop-3.2.0/share/hadoop/mapreduce/hadoop-mapreduce-examples-3.2.0.jar wordcount /input /output
你可以加一下慕课的大数据学习qun 938632081 方便沟通
看下你代码的第32行,错误信息提示的是数组角标越界了
代码已上传至网盘?
链接:https://pan.baidu.com/s/1JJ5AHDOd3gIXJmo6g08Btg
提取码:ghbt
一般出现这种情况是因为依赖包没有下载成功,你可以到你本地的maven仓库中确认一下对应的jar包是否成功下载
或者尝试重新强制下载依赖,使用命令 mvn clean compile
这个项目是一个maven项目,在idea工具中直接新建maven项目即可达到视频中的样子
需要引入hadoop中的包
import org.apache.hadoop.conf.Configuration;
恩 使用export是定义环境变量的,针对框架的安装部署一定要仔细检查各种配置哈,稍微不注意就掉坑里面了?
下载失败一般是由于网络问题导致的
首先去本地的maven仓库找到之前下载的hadoop-client,把这个目录直接删除掉,因为有可能有个别jar包之前由于网络原因导致下载的不完整
然后可以修改maven的镜像地址,可以改为阿里云的
配置文件在apache-maven-3.x.x\conf\settings.xml
<mirrors>
<mirror>
<id>alimaven</id>
<name>aliyun maven</name>
<url>http://maven.aliyun.com/nexus/content/groups/public/</url>
<mirrorOf>central</mirrorOf>
</mirror>
</mirrors>
修改好以后,可以选在idea中重新加载maven依赖,或者在命令行下执行mvn clean compile即可重新下载缺少的依赖
/创建静态内部类MyMapper
public static class MyMapper extends Mapper<LongWritable,Text,Text,LongWritable>{
//调用自带的map()函数
protected void map(LongWritable k1,Text v1,Context context)
throws IOException,InterruptedException{
//k1代表的是每一行的偏移量,v1代表的是每一行的内容
//将传送进来的每一行数据切割,切割成单词
String[] words =v1.toString().split(" ");
//迭代切割出来的单词数据
for(String word:words) {
//将迭代出来的单词数据封装成<k2,v2>
Text k2 =new Text(word);
LongWritable v2=new LongWritable();
//把<k2,v2>写出去
context.write(k2, v2);
}
}
}
//创建自定义静态内部类MyReducer
public static class MyReducer extends Reducer<Text,LongWritable,Text,LongWritable>{
/*
* 针对v2s做累加求和,并且最终把<k3,v3>写出去
*/
protected void reducer(Text k2,Iterable<LongWritable> v2s,Context context)
throws IOException,InterruptedException{
//创建一个表量sum来保存v2s的累加值
long sum=0;
for(LongWritable v2:v2s) {
sum=sum+v2.get();
}
//组装<k3,v3>
Text k3=k2;
LongWritable v3=new LongWritable(sum);
//把组装好的<k3,v3>写出去
context.write(k3, v3);
}
}
代码好像没什么问题?
hadoop的mapred-site.xml yarn-site.xml core-cite.xml 等配置文件中的配置较多,此课程中暂时没有针对里面的参数做详细解释,如果对这块感兴趣的话可以先到网上查找一下公开资料,后面会有针对hadoop的高级课程会分析里面的参数?