1、创建一个maven工程

2、POM文件

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion> <groupId>com.sogou</groupId>
<artifactId>teemo-dc-etl</artifactId>
<version>1.0.0</version>
<packaging>jar</packaging> <name>teemo-dc-etl</name>
<url>http://maven.apache.org</url> <properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<mahout.version>0.5</mahout.version>
<mahout.groupid>org.apache.mahout</mahout.groupid>
<spring.version>3.0.6.RELEASE</spring.version>
</properties> <repositories>
<repository>
<id>maven-ali</id>
<url>http://maven.twttr.com/</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
<updatePolicy>always</updatePolicy>
<checksumPolicy>fail</checksumPolicy>
</snapshots>
</repository>
</repositories> <dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency> <dependency>
<groupId>org.apache.hadoop</groupId>
<artifactId>hadoop-hdfs</artifactId>
<version>2.5.0</version>
</dependency> <dependency>
<groupId>org.apache.hadoop</groupId>
<artifactId>hadoop-client</artifactId>
<version>2.5.1</version>
</dependency> <dependency>
<groupId>org.apache.hadoop</groupId>
<artifactId>hadoop-common</artifactId>
<version>2.5.0</version>
</dependency> <dependency>
<groupId>com.hadoop.gplcompression</groupId>
<artifactId>hadoop-lzo</artifactId>
<version>0.4.19</version>
</dependency> <dependency>
<groupId>org.apache.hadoop</groupId>
<artifactId>hadoop-yarn-common</artifactId>
<version>2.5.2</version>
</dependency> <dependency>
<groupId>com.alibaba</groupId>
<artifactId>fastjson</artifactId>
<version>1.2.4</version>
</dependency> </dependencies> <build>
<plugins>
<!--
bind the maven-assembly-plugin to the package phase
this will create a jar file without the storm dependencies
suitable for deployment to a cluster.
-->
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<configuration>
<archive>
<manifest>
<mainClass></mainClass>
</manifest>
</archive>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
</configuration>
<executions>
<execution>
<id>make-assembly</id>
<phase>package</phase> <!-- packaging phase -->
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.6</source>
<target>1.6</target>
<encoding>UTF-8</encoding>
</configuration>
</plugin> <plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.14.1</version>
<configuration>
<argLine>-Xmx2048m</argLine>
</configuration>
</plugin>
</plugins>
</build>
</project>
这里有个lzo包,需要增加twiter的资源库
3、mapreduce文件写法
package com.sogou.teemo.test;

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; import java.io.IOException;
import java.util.StringTokenizer; public class WordCount {
/* Mapper */
public static class TokenizerMapper extends Mapper<Object, Text, Text, IntWritable> {
private final static IntWritable one = new IntWritable(1);
private Text word = new Text();
@Override
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);
}
}
} /* Reducer */
public static class IntSumReducer extends Reducer<Text,IntWritable,Text,IntWritable>{
private IntWritable result = new IntWritable();
@Override
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);
}
} /* 启动 MapReduce Job */
public static void main(String[] args) throws Exception{
System.setProperty("hadoop.home.dir","D:/hadoop-2.6.5" );
Configuration conf = new Configuration();
/*if(args.length != 2){
System.err.println("Usage: wordcount <int> <out>");
System.exit(2);
}*/
String arg1 = "input";
String arg2 = "output";
Job job = new Job(conf, "word count");
job.setJarByClass(WordCount.class);
job.setMapperClass(TokenizerMapper.class);
job.setReducerClass(IntSumReducer.class);
job.setOutputKeyClass(Text.class);
job.setOutputValueClass(IntWritable.class);
FileInputFormat.addInputPath(job,new Path(arg1));
FileOutputFormat.setOutputPath(job,new Path(arg2));
System.exit(job.waitForCompletion(true)?0:1);
}
}
												

intelij创建MapReduce工程的更多相关文章

  1. 实训任务03: 使用Eclipse创建MapReduce工程

    实训任务03: 使用Eclipse创建MapReduce工程 实训1: win7中使用Eclipse创建MapReduce工程 实训2:Centos 6.8系统中安装Eclipse 一.下载Eclip ...

  2. MapReduce工程(IDEA)

    MapReduce工程(IDEA) hadoop 1. maven工程 1.1 创建maven工程 1.2 修改配置文件 1.3 Mapper类 1.4 Reduces类 1.5 Driver类 1. ...

  3. Eclipse创建Maven工程报错

    问题 用Eclipse创建maven工程的时候,总是会报错,例如提示: Unable to create project from archetype [org.apache.maven.archet ...

  4. MyEclipse创建Maven工程

    先要在MyEclipse中对Maven进行设置:

  5. Vivado SDK 2014.2 创建新工程后,BSP版本不对的解决办法

    问题描述如下: 1. 使用Vivado SDK 2014.2已经创建了工程,但是此时,hdf文件增加了外设,需要重新创建工程以更新SDK中的外设描述: 2. 使用新的hdf创建工程后,发现system ...

  6. 关于Xcode6创建的工程在Xcode5打开

    Xcode6创建的工程在Xcode5打开- 4.0只显示3.5大小的问题 只需要在工程里添加Default-568h@2x.png,即可以解决

  7. windows下无法创建django工程的问题

    环境:python2.7  django1.7 安装好django后,将C:\Python27\Lib\site-packages\Django-1.7.7-py2.7.egg\django\bin; ...

  8. 在VS2015 RC打开CTP中创建的工程

    VS2015终于出了RC了!小伙伴们快来安装试用吧,地址在这里,还有新的Windows 10开发工具哦,要不然是开发不了Universal Windows App的,安装前记得卸载CTP版本. 新的R ...

  9. iOS创建子工程

    实际开发中,我们可能会同时开发好几个端,比如楼主目前开发的家教平台,需要老师端,家长端,助教端三个端.有很多工具方法,或者封装的自定义控件都是可以复用的.我们就可以把公用的代码抽取出去,新建一个工程, ...

随机推荐

  1. C语言sscanf用法解析与正则表达式支持

    最近学习算法和输入输出用到的基本知识,首先是我自己写的一份代码参考和学习了很多资源 后面会给出参考资料,他们写得更加详细,正则表达式的支持确实是一大亮点所在 #include<iostream& ...

  2. PHP解析xml文件时报错:I/O warning : failed to load external entity

    在代码顶部增加 libxml_disable_entity_loader(false); libxml_disable_entity_loader()作用是设置是否禁止从外部加载XML实体,设为tru ...

  3. linux $* $@ 特定位置参数

    举例说:脚本名称叫test.sh 入参三个: 1 2 3运行test.sh 1 2 3后$*为"1 2 3"(一起被引号包住)$@为"1" "2&qu ...

  4. Hadoop专业解决方案-第13章 Hadoop的发展趋势

    一.前言: 非常感谢Hadoop专业解决方案群:313702010,兄弟们的大力支持,在此说一声辛苦了,经过两周的努力,已经有啦初步的成果,目前第13章 Hadoop的发展趋势小组已经翻译完成,在此对 ...

  5. [转]my97 datepicker IE9+ 故障修复方法

    转自:http://blog.csdn.net/xuwj1984/article/details/38733483 问题1:my97 datepicker 不能弹出日期下拉框. 解决方法: 1.下载最 ...

  6. VBA 自动得到分数

    ' 将一个正数除以 y 返回一个整数或分数 Function RFs(ByVal x As Integer) As String Then RFs = Exit Function End If Dim ...

  7. 如何使input双击时不显示历史记录

    原文地址:http://highping.iteye.com/blog/359428 HTML的输入框可以拥有自动完成的功能,当你往输入框输入内容的时候,浏览器会从你以前的同名输入框的历史记录中查找出 ...

  8. 数据读取速度达1.5G/s,UFS 2.1存储技术曝光

    目前最快的是苹果NVME,当然UFS2.1也不差 iPhone6s与iPhone6s Plus在硬件的规格上有了很大的提升,但是它们身上的变化远没有苹果在发布会上所提到的A9处理器.1200万摄像头以 ...

  9. JpGraph使用详解http://5ydycm.blog.51cto.com/115934/177498 http://www.cnblogs.com/txw1958/archive/2013/08/18/php-charts.html

    下载 在官方网站 http://www.aditus.nu/jpgraph/ 下载jpgraph,其中1.X系列是用于PHP4的,2.X系列是用于PHP5的. 安装 将下载的得到的jpgraph压缩文 ...

  10. PHP下载文件的几种方案

    PHP下载远程文件的3种方法以及性能考虑 2014-02-21      0个评论       收藏    我要投稿 今天在做导出Excel的时候,总是要测试导出的Excel文件,频繁的下载和打开,很 ...