Follow my previous question, I put the complete code as 
follows, I doubt is there any method to get this working on 
0.20.X using the new API.

The command I executed was: 

bin/hadoop jar myjar.jar FileTest -files textFile.txt /input/ 
/output/

The complete code: 

public class FileTest extends Configured implements Tool {
       private static final Logger sLogger = 
Logger.getLogger(FileTest.class);

       public static class Map extends 
org.apache.hadoop.mapreduce.Mapper<LongWritable, Text, Text, 
Text>{
           Text word;

           public void 
setup(org.apache.hadoop.mapreduce.Mapper<LongWritable, Text, 
Text, Text>.Context context){
               String line;
               try{
                   File z1_file = new File("textFile.txt");
                   BufferedReader bf = new BufferedReader(new 
FileReader(z1_file));
                   while ((line=bf.readLine())!=null){

                       word = new Text(line);
                   }

               } catch(IOException ioe){
                   sLogger.error(ioe.toString());
               }
           }

            public void map(LongWritable key, Text value, 
org.apache.hadoop.mapreduce.Mapper.Context context) throws 
IOException, InterruptedException{
                     context.write(new Text("test"), word);
                }
       }


       public int run(String[] args) throws 
IOException,URISyntaxException {
            GenericOptionsParser parser = new 
GenericOptionsParser(args);
            Configuration conf = parser.getConfiguration();
            String[] otherArgs = parser.getRemainingArgs();
            Job job = new Job(conf, "MyJob");

            Path in = new Path(otherArgs[0]);
            Path out = new Path(otherArgs[1]);

           
org.apache.hadoop.mapreduce.lib.input.FileInputFormat.setInput
Paths(job, in);
           
org.apache.hadoop.mapreduce.lib.output.FileOutputFormat.setOut
putPath(job, out);

            job.setJarByClass(FileTest.class);
            job.setMapperClass(FileTest.Map.class);

            job.setNumReduceTasks(0);
            job.setMapOutputKeyClass(Text.class);
            job.setMapOutputValueClass(Text.class);

            try {
                System.exit(job.waitForCompletion(true) ? 0 : 
1);
                 return 0;
            }catch( Throwable e) {
                  sLogger.error( "Job failed ", e);
                 return -1;
            }
       }

       public static void main(String[] args) throws Exception 
{
            int exitCode = ToolRunner.run(new 
FileTest(),args);
            System.exit(exitCode);
       }

}

Reply via email to