public static Job parseInputAndOutput(Tool tool, Configuration conf, String[] args) throws IOException { if (args.length != 2) { printUsage(tool, "<input> <output>"); return null; } Job job = Job.getInstance(conf); job.setJobName("test"); job.setJarByClass(tool.getClass()); FileInputFormat.addInputPath(job, new Path(args[0])); FileOutputFormat.setOutputPath(job, new Path(args[1])); return job; }
private static int launch(Configuration conf, Tool tool, String[] args) throws Exception { if (LOG.isDebugEnabled()) { LOG.debug( MessageFormat.format( "Launching application: {0}{1}", //$NON-NLS-1$ tool.getClass().getName(), Arrays.toString(args))); } ClassLoader contextClassLoader = switchContextClassLoader(conf.getClassLoader()); try { return ToolRunner.run(conf, tool, args); } finally { switchContextClassLoader(contextClassLoader); } }
public static void printUsage(Tool tool, String extraArgsUsage) { System.err.printf( "Usage: %s [genericOptions] %s\n\n", tool.getClass().getSimpleName(), extraArgsUsage); GenericOptionsParser.printGenericCommandUsage(System.err); }