java - CSV 类未找到异常

标签 java hadoop mapreduce hbase opencsv

我有一个在 hdfs 中上传的 CSV 文件。我正在使用 opencsv 解析器来读取数据。我在 hadoop 类路径中也有我的 jar 文件,并将其上传到 hdfs 中的以下位置/jars/opencsv-3.9.jar。我收到的错误也已附上。

这是我的代码片段

public class TermLabelledPapers {

   public static class InputMapper extends Mapper<LongWritable, Text, Text, Text> {

    @Override
    protected void map(LongWritable key, Text value, Context context)
            throws IOException, InterruptedException {

        CSVParser parser = new CSVParser();
        String[] lines = parser.parseLine(value.toString());
        //readEntry.readHeaders();
        String doi = lines[0];
        String keyphrases = lines[3];

        Get g = new Get(Bytes.toBytes(doi.toString()));
        context.write(new Text(doi), new Text(keyphrases));

    }
}

public static class PaperEntryReducer extends TableReducer<Text, Text, ImmutableBytesWritable> {

    @Override
    protected void reduce(Text doi, Iterable<Text> values, Context context)
            throws IOException, InterruptedException {

    }
}


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

    Configuration conf = HBaseConfiguration.create();
    conf.set("hbase.zookeeper.quorum", "172.17.25.18");
    conf.set("hbase.zookeeper.property.clientPort", "2183");
    //add the external jar to hadoop distributed cache 
    //addJarToDistributedCache(CsvReader.class, conf);

    Job job = new Job(conf, "TermLabelledPapers");
    job.setJarByClass(TermLabelledPapers.class);
    job.setMapperClass(InputMapper.class);
    job.setMapOutputKeyClass(Text.class);
    job.setMapOutputValueClass(Text.class);
    job.addFileToClassPath(new Path("/jars/opencsv-3.9.jar"));
    FileInputFormat.setInputPaths(job, new Path(args[0]));  // "metadata.csv"

    TableMapReduceUtil.initTableReducerJob("PaperBagofWords", PaperEntryReducer.class, job);
    job.setReducerClass(PaperEntryReducer.class);
    job.waitForCompletion(true);
 }

}

运行作业后出现的错误是

Error: java.lang.ClassNotFoundException: com.csvreader.CsvReader
 at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
at mcad.TermLabelledPapers$InputMapper.map(TermLabelledPapers.java:69)
at mcad.TermLabelledPapers$InputMapper.map(TermLabelledPapers.java:1)
at org.apache.hadoop.mapreduce.Mapper.run(Mapper.java:146)
at org.apache.hadoop.mapred.MapTask.runNewMapper(MapTask.java:787)
at org.apache.hadoop.mapred.MapTask.run(MapTask.java:341)
at org.apache.hadoop.mapred.YarnChild$2.run(YarnChild.java:164)
at java.security.AccessController.doPrivileged(Native Method)
at javax.security.auth.Subject.doAs(Subject.java:422)
at org.apache.hadoop.security.UserGroupInformation.doAs(UserGroupInformation.java:1657)
at org.apache.hadoop.mapred.YarnChild.main(YarnChild.java:158)

最佳答案

理想情况下,如果 hadoop 类路径中的 jar 不应该出现此错误。如果你是一个 maven 项目,你可以尝试创建 jar-with-dependencies,它将包含所有依赖的 jar 和你的 jar。这有助于诊断问题。

关于java - CSV 类未找到异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42460985/

相关文章:

java - JPA 实体及其自定义功能

hadoop - 创建外部临时表时在Hive中使用SQL保留字

hadoop - 使用配置单元在大范围分区中选择数据

hadoop - Map Reduce 的对象序列化

database - 对Hadoop DFS和MapReduce的一些疑问

java - 如何使用 Bamboo 开始 Play,而不需要永远继续部署?

java - 如何使用 fragment 将标题放入 ViewPager?

hadoop - 为每个映射器输出准确运行组合器的时间

java - 以编程方式设置 Controller 时为 "No Controller specified for top level element"

hadoop - Hadoop和httpfs安装困难