gpt4 book ai didi

eclipse - 映射减少分布式缓存

转载 作者:行者123 更新时间:2023-12-02 21:47:06 24 4
gpt4 key购买 nike

我无法在job.waitforcompletion(boolean)子句上编译我的DriverClass。它给了我NoClassFoundException。如果我捕获到该异常,则run方法会抛出它期望一个int值的错误。我正在使用MapReduce New API。任何人都可以提出问题的答案:

import java.io.File;
import java.io.IOException;
import java.net.URI;
import java.net.URISyntaxException;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.conf.Configured;
import org.apache.hadoop.filecache.DistributedCache;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.util.GenericOptionsParser;
import org.apache.hadoop.util.Tool;
import org.apache.hadoop.util.ToolRunner;
import org.apache.hadoop.mapreduce.Job;
import org.apache.hadoop.mapreduce.lib.input.FileInputFormat;
import org.apache.hadoop.mapreduce.lib.input.KeyValueTextInputFormat;
import org.apache.hadoop.mapreduce.lib.input.TextInputFormat;
import org.apache.hadoop.mapreduce.lib.output.FileOutputFormat;
import org.apache.hadoop.mapreduce.lib.output.TextOutputFormat;


public class Dist_Driver extends Configured implements Tool {

public int run(String args[]) throws IOException, InterruptedException {

// Configuration phase
// Configuration conf=new Configuration();
Job job = new Job(new Configuration());
job.setJarByClass(Dist_Driver.class);

// Mapper Reducer InputFormat
job.setInputFormatClass(FileInputFormat.class);
// Mapper and Reducer Class
job.setMapperClass(Dist_Mapper.class);
job.setReducerClass(DistCache_Reducer.class);

job.setOutputFormatClass(TextOutputFormat.class);
job.setInputFormatClass(KeyValueTextInputFormat.class);
// set FileInputOutput
FileInputFormat.addInputPath(job, new Path(args[0]));
FileOutputFormat.setOutputPath(job, new Path(args[1]));
// setting number of reduce tasks and submit it
job.setNumReduceTasks(2);

// Lets check if the file exist
File f1 = new File("/home/hdfs/trials_mapreduce_progams/emp_id");
if (f1.exists())
System.out.println("The Files Exists");
else
System.out.println("The File doesnot exist");
URI path1;
try {
path1 = new URI(
"/home/hdfs/trials_mapreduce_progams/emp_lookup.txt");
DistributedCache.addCacheFile(path1, job.getConfiguration());
} catch (URISyntaxException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}

if (job.waitForCompletion(true))
return 0;
else
return 1;

}

public static void main(String[] args) throws Exception {

int exitcode = ToolRunner.run(new Dist_Driver(), args);
System.exit(exitcode);

}

}

最佳答案

只需将ClassNotFoundException添加到run方法签名中

public int run(String args[]) throws IOException, 
InterruptedException,
ClassNotFoundException {

尝试使用 try/catch时出错的原因是,如果在执行过程中抛出 ClassNotFoundException,则将没有返回值,并且该方法必须返回某些内容。

如果您真的想捕获它,只需在 return 1子句中添加 catch,这是错误退出代码

关于eclipse - 映射减少分布式缓存,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24229486/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com