hadoop eclipse maven wordcount

package com.zm.hadoop;

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.net.URI;

import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.FSDataInputStream;
import org.apache.hadoop.fs.FSDataOutputStream;
import org.apache.hadoop.fs.FileSystem;
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.lib.input.FileInputFormat;
import org.apache.hadoop.mapreduce.lib.map.TokenCounterMapper;
import org.apache.hadoop.mapreduce.lib.output.FileOutputFormat;
import org.apache.hadoop.mapreduce.lib.reduce.IntSumReducer;

/**
 * Hello world!
 *
 */
public class App 
{
    public static void main( String[] args )
    {   
     try {
    		
             Configuration conf = new Configuration();

     		// 这个解决hdfs问题
             conf.set("fs.hdfs.impl", org.apache.hadoop.hdfs.DistributedFileSystem.class.getName());
     		// 这个解决本地file问题
             conf.set("fs.file.impl", org.apache.hadoop.fs.LocalFileSystem.class.getName());
          
             Job job = Job.getInstance(conf, "word count");
             job.setJarByClass(App.class);
             job.setMapperClass(TokenCounterMapper.class);
             job.setCombinerClass(IntSumReducer.class);
             job.setReducerClass(IntSumReducer.class);
             job.setOutputKeyClass(Text.class);
             job.setOutputValueClass(IntWritable.class);
             
             String filePath = "hdfs://192.168.110.128:9000/test/README.txt";
             String filePath1 = "hdfs://192.168.110.128:9000/test/README1.txt";
             
             FileInputFormat.addInputPath(job, new Path(   (filePath) ));
            FileOutputFormat.setOutputPath(job, new Path(   (filePath1)  ));

             System.exit(job.waitForCompletion(true) ? 0 : 1);
             
              
             
         } catch (Exception e) {
             e.printStackTrace();
         }
 
    }
}

  4.0.0

  com.zm
  hadoop
  0.0.1-SNAPSHOT
  jar

  hadoop
  http://maven.apache.org

  
  3.2.0
  
    UTF-8
  

  
  

	org.apache.hadoop
	hadoop-client
	${hadoop.version}

 

	org.apache.hadoop
	hadoop-common
	${hadoop.version}

 

	org.apache.hadoop
	hadoop-hdfs
	${hadoop.version}

 
 
 org.apache.hadoop
 hadoop-mapreduce-client-common
 ${hadoop.version}




 org.apache.hadoop
 hadoop-mapreduce-client-jobclient
 ${hadoop.version}

 


    
      junit
      junit
      3.8.1
      test
    
  
  
        
                       
        org.apache.maven.plugins
        maven-shade-plugin
        1.2.1
        
            
                package
                
                        shade
                
                    
                        
                            
                                com.zm.hadoop.App
                            
                        
                    
            
        
     

 
        
        
            
                org.apache.maven.plugins
                maven-compiler-plugin
                
                    1.8
                    1.8
                
            

        
    
 

 

你可能感兴趣的:(hadoop)