3 回答
TA贡献1876条经验 获得超5个赞
哦,请不要使用runJar,Java API非常好。
了解如何从常规代码开始工作:
// create a configuration
Configuration conf = new Configuration();
// create a new job based on the configuration
Job job = new Job(conf);
// here you have to put your mapper class
job.setMapperClass(Mapper.class);
// here you have to put your reducer class
job.setReducerClass(Reducer.class);
// here you have to set the jar which is containing your
// map/reduce class, so you can use the mapper class
job.setJarByClass(Mapper.class);
// key/value of your reducer output
job.setOutputKeyClass(Text.class);
job.setOutputValueClass(Text.class);
// this is setting the format of your input, can be TextInputFormat
job.setInputFormatClass(SequenceFileInputFormat.class);
// same with output
job.setOutputFormatClass(TextOutputFormat.class);
// here you can set the path of your input
SequenceFileInputFormat.addInputPath(job, new Path("files/toMap/"));
// this deletes possible output paths to prevent job failures
FileSystem fs = FileSystem.get(conf);
Path out = new Path("files/out/processed/");
fs.delete(out, true);
// finally set the empty out path
TextOutputFormat.setOutputPath(job, out);
// this waits until the job completes and prints debug out to STDOUT or whatever
// has been configured in your log4j properties.
job.waitForCompletion(true);
如果您使用的是外部群集,则必须通过以下方式将以下信息放入配置中:
// this should be like defined in your mapred-site.xml
conf.set("mapred.job.tracker", "jobtracker.com:50001");
// like defined in hdfs-site.xml
conf.set("fs.default.name", "hdfs://namenode.com:9000");
当hadoop-core.jar位于您的应用程序容器类路径中时,这应该没问题。但是我认为您应该在网页上放置某种进度指示器,因为完成一项Hadoop工作可能需要几分钟到几小时;)
对于YARN(> Hadoop 2)
对于YARN,需要设置以下配置。
// this should be like defined in your yarn-site.xml
conf.set("yarn.resourcemanager.address", "yarn-manager.com:50001");
// framework is now "yarn", should be defined like this in mapred-site.xm
conf.set("mapreduce.framework.name", "yarn");
// like defined in hdfs-site.xml
conf.set("fs.default.name", "hdfs://namenode.com:9000");
TA贡献1788条经验 获得超4个赞
因为映射和减少在不同机器上的运行,所以所有引用的类和jar必须在机器之间移动。
如果您有程序包jar,并且在您的桌面上运行,则@ThomasJungblut的答案是可以的。但是,如果您在Eclipse中运行,请右键单击您的类并运行,它不起作用。
代替:
job.setJarByClass(Mapper.class);
使用:
job.setJar("build/libs/hdfs-javac-1.0.jar");
同时,您的jar清单必须包含Main-Class属性,这是您的主类。
对于gradle用户,可以将这些行放在build.gradle中:
jar {
manifest {
attributes("Main-Class": mainClassName)
}}
添加回答
举报