之前一直用Hadoop streaming方式,-file功能非常实用,可以动态上传文件,例如一些配置文件等。之后开始寻找java程序中的-file功能,费了很大功夫,一直没有测试通过。后来发现GenericOptionsParser能解析一些特有命令参数,并且做相应处理,例如:遇到-files参数时,将文件上传到mapper节点。经过测试,-files命令参数必须在hadoop jar后紧接着,这个可以通过streaming来查看使用规范,如下:Usage: $HADOOP_HOME/bin/hadoop jar $HADOOP_HOME/hadoop-streaming.jar [options] Options: -input <path> DFS input file(s) for the Map step -output <path> DFS output directory for the Reduce step -mapper <cmd|JavaClassName> The streaming command to run -combiner <cmd|JavaClassName> The streaming command to run -reducer <cmd|JavaClassName> The streaming command to run -file <file> File/dir to be shipped in the Job jar file. Deprecated. Use generic option "-files" instead -inputformat TextInputFormat(default)|SequenceFileAsTextInputFormat|JavaClassName Optional. -outputformat TextOutputFormat(default)|JavaClassName Optional. -partitioner JavaClassName Optional. -numReduceTasks <num> Optional. -inputreader <spec> Optional. -cmdenv <n>=<v> Optional. Pass env.var to streaming commands -mapdebug <path> Optional. To run this script when a map task fails -reducedebug <path> Optional. To run this script when a reduce task fails -io <identifier> Optional. -lazyOutput Optional. Lazily create Output -verbose Generic options supported are -conf <configuration file> specify an application configuration file -D <property=value> use value for given property -fs <local|namenode:port> specify a namenode -jt <local|jobtracker:port> specify a job tracker -files <comma separated list of files> specify comma separated files to be copied to the map reduce cluster -libjars <comma separated list of jars> specify comma separated jar files to include in the classpath. -archives <comma separated list of archives> specify comma separated archives to be unarchived on the compute machines.The general command line syntax is bin/hadoop command [genericOptions] [commandOptions]hadoop 执行java程序也需要遵循该命令参数规范,特别是-D -libjars -files等参数。测试代码:package wordcount.com.cn;