2013-02-08 90 views
0

我一直在嘗試對hadoop使用pagerank算法,並且在初始化作業時遇到了一些問題。嘗試在Hadoop中開始工作時發生錯誤

當我嘗試使用作業類,使初始化我對編譯以下錯誤:在線程

異常「主要」 java.lang.NoClassDefFoundError:組織/阿帕奇/公/在組織日誌/的LogFactory 。.apache.hadoop.mapreduce.Job(Job.java:89) 在Pagerank.main(Pagerank.java:244)

下面是代碼:

Job job; 
job = new Job(); 
job.setJarByClass(Pagerank.class);  // In what class are our map/reduce functions for this job found? 
job.setMapperClass(PRMap.class);  // What is our map function for this job? 
job.setReducerClass(PRReduce.class); // What is our reduce function for this job? 

job.setOutputKeyClass(Text.class);    // What are the (hadoop.io compliant) datatype for our 
job.setOutputValueClass(Text.class);   // reducer output's key-value pairs? 
job.setInputFormatClass(TextInputFormat.class);  // How will the mapper distinguish (key value) record inputs? 
FileInputFormat.addInputPath(job, new Path(args[0])); // First command line argument 
FileOutputFormat.setOutputPath(job, new Path("temp0")); 
job.waitForCompletion(true); 

當我嘗試做使用JobConf Cla進行初始化ss我在使用的一些方法上得到了一個錯誤。

下面是代碼:

 JobConf conf = new JobConf(Pagerank.class); 
    conf.setJobName("pagerank"); 

    conf.setOutputKeyClass(Text.class); 
    conf.setOutputValueClass(Text.class); 

    conf.setMapperClass(PRMap.class); 
    conf.setReducerClass(PRReduce.class); 

    conf.setInputFormat(TextInputFormat.class); 
    conf.setOutputFormat(TextOutputFormat.class); 

    FileInputFormat.setInputPaths(conf, new Path(args[0])); 
    FileOutputFormat.setOutputPath(conf, new Path(args[1])); 

    JobClient.runJob(conf); 

根據該錯誤:

類JobConf方法setMapperClass不能被應用到給定的類型;

要求:?類擴展映射器

發現:類PRMap

原因:實際參數類PRMap不能轉換到類擴展映射器通過方法調用轉換

似乎我無法通過PRMap.class作爲setMapperClass中的參數,儘管我寫的PRMap類遵循Hadoop的Map函數標準

public static class PRMap extends Mapper<LongWritable, Text, Text, Text> 
{ ... } 

對這兩種方法有何建議?

回答

1

嘗試將包含org.apache.commons.Logging.LogFactory jar的jar放入每臺機器的HadoopHome的Lib目錄中並重新啓動羣集。

或者您可以嘗試使用libjars選項通過命令行添加jar。 爲:

hadoop jar myjar.jar package.classname -libjars mypath/common-loggings.jar

+0

謝謝!這解決了這個特殊的問題。 – user2052763

1

在您的主要方法中添加此行。

DistributedCache.addFileToClassPath(new Path("<Absolute Path>/common-loggings.jar"), conf); 
0

這是因爲映射器無法找到LogFactory,這是common-loggings.jar一部分。爲此,必須讓每個客戶端映射器都可以訪問它,通過將jar複製到所有機器或其他有效的方法是通過複製到分佈式緩存。

$bin/hadoop fs -copyFromLocal mylib.jar /myapp/mylib.jar 
And accessing it from you code 
DistributedCache.addFileToClassPath(new Path("/myapp/mylib.jar"), job); 

更可以發現here

相關問題