第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問(wèn)題,去搜搜看,總會(huì)有你想問(wèn)的

從簡(jiǎn)單的Java程序調(diào)用mapreduce作業(yè)

從簡(jiǎn)單的Java程序調(diào)用mapreduce作業(yè)

手掌心 2019-11-27 14:42:41
我一直試圖從同一程序包中的簡(jiǎn)單Java程序調(diào)用mapreduce作業(yè)。.我試圖在java程序中引用mapreduce jar文件,并runJar(String args[])通過(guò)傳遞mapreduce作業(yè)的輸入和輸出路徑,使用該方法調(diào)用它..但是該程序可以正常工作..我如何運(yùn)行這樣的程序,在該程序中,我只使用傳遞輸入,輸出和jar路徑的主要方法?是否可以通過(guò)它運(yùn)行mapreduce作業(yè)(jar)?我想要這樣做是因?yàn)槲乙粋€(gè)接一個(gè)地運(yùn)行多個(gè)mapreduce作業(yè),其中我的Java程序vl通過(guò)引用其jar文件來(lái)調(diào)用每個(gè)此類(lèi)作業(yè)。如果可能的話,我不妨只使用一個(gè)簡(jiǎn)單的servlet進(jìn)行此類(lèi)調(diào)用并出于圖形目的參考其輸出文件。/* * To change this template, choose Tools | Templates * and open the template in the editor. *//** * * @author root */import org.apache.hadoop.util.RunJar;import java.util.*;public class callOther {    public static void main(String args[])throws Throwable    {        ArrayList arg=new ArrayList();        String output="/root/Desktp/output";        arg.add("/root/NetBeansProjects/wordTool/dist/wordTool.jar");        arg.add("/root/Desktop/input");        arg.add(output);        RunJar.main((String[])arg.toArray(new String[0]));    }}
查看完整描述

3 回答

?
慕運(yùn)維8079593

TA貢獻(xiàn)1876條經(jīng)驗(yàn) 獲得超5個(gè)贊

哦,請(qǐng)不要使用runJar,Java API非常好。


了解如何從常規(guī)代碼開(kāi)始工作:


// 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);

如果您使用的是外部群集,則必須通過(guò)以下方式將以下信息放入配置中:


// 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");

當(dāng)hadoop-core.jar位于您的應(yīng)用程序容器類(lèi)路徑中時(shí),這應(yīng)該沒(méi)問(wèn)題。但是我認(rèn)為您應(yīng)該在網(wǎng)頁(yè)上放置某種進(jìn)度指示器,因?yàn)橥瓿梢豁?xiàng)Hadoop工作可能需要幾分鐘到幾小時(shí);)


對(duì)于YARN(> Hadoop 2)


對(duì)于YARN,需要設(shè)置以下配置。


// 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");


查看完整回答
反對(duì) 回復(fù) 2019-11-27
?
尚方寶劍之說(shuō)

TA貢獻(xiàn)1788條經(jīng)驗(yàn) 獲得超4個(gè)贊

因?yàn)橛成浜蜏p少在不同機(jī)器上的運(yùn)行,所以所有引用的類(lèi)和jar必須在機(jī)器之間移動(dòng)。


如果您有程序包jar,并且在您的桌面上運(yùn)行,則@ThomasJungblut的答案是可以的。但是,如果您在Eclipse中運(yùn)行,請(qǐng)右鍵單擊您的類(lèi)并運(yùn)行,它不起作用。


代替:


job.setJarByClass(Mapper.class);

使用:


job.setJar("build/libs/hdfs-javac-1.0.jar");

同時(shí),您的jar清單必須包含Main-Class屬性,這是您的主類(lèi)。


對(duì)于gradle用戶(hù),可以將這些行放在build.gradle中:


jar {

manifest {

    attributes("Main-Class": mainClassName)

}}


查看完整回答
反對(duì) 回復(fù) 2019-11-27
  • 3 回答
  • 0 關(guān)注
  • 871 瀏覽
慕課專(zhuān)欄
更多

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購(gòu)課補(bǔ)貼
聯(lián)系客服咨詢(xún)優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)