Windows Eclipse configuration Hadoop plugin (iv)

Source: Internet
Author: User

1. Copy the plugin Hadoop-eclipse-plugin-2.6.2.jar to the plugins in the Eclipse installation directory

2. Restart Eclipse
Preparing Hadoop

3. Enter Map/reduce view mode


4. Storing data in a Hadoop distributed storage System

5. Connect to Hadoop


6. Create a Hadoop project

7. Create a class Mywordcount.java

Package Com.yc.hadoop;import Java.io.ioexception;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;public class Mywordcount {public static class Mywordcoun Tmapper extends Mapper<object, text, text, intwritable> {Private final static intwritable one = new                Intwritable (1);                Private text Word = new text (); public void Map (Object key, Text value, Context context) throws IOException, interruptedexception {S                      tring[] Words = value.tostring (). Split ("\\s");                            for (String w:words) {word.set (w); ConteXt.write (Word, one); }}} public static class Mywordcountreducer extends Reducer<text, intwritable, Text,                intwritable> {Private Intwritable result = new intwritable (); 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); }} public static void Main (string[] args) throws Exception {Configuration conf = new Co                Nfiguration ();                Job Job = job.getinstance (conf, "Mywordcount");                Job.setjarbyclass (Mywordcount.class);                Job.setmapperclass (Mywordcountmapper.class); Job.setcombinerclass (MywordcoUntreducer.class);                Job.setreducerclass (Mywordcountreducer.class);                Job.setoutputkeyclass (Text.class);                Job.setoutputvalueclass (Intwritable.class);                Fileinputformat.addinputpath (Job, New Path (Args[0]));                Fileoutputformat.setoutputpath (Job, New Path (Args[1]));          System.exit (Job.waitforcompletion (true)? 0:1); }    }

8. Running the Hadoop project

Windows Eclipse configuration Hadoop plugin (iv)

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.