2014-09-26 46 views
0

获取此异常用Hadoop 2.5.1一个HTTP Servlet中org.apache.hadoop.fs.FileSystem:提供org.apache.hadoop.hdfs.DistributedFileSystem不是一个亚型

java.util.ServiceConfigurationError: org.apache.hadoop.fs.FileSystem: Provider org.apache.hadoop.hdfs.DistributedFileSystem not a subtype 

的DistributedFileSystem类内使用时可在这些罐子

hadoop-core-1.2.1.jar 
hadoop-hdfs-2.5.1.jar 

发现当我单独使用Hadoop的核心1.2.1.jar,编译器错误,我得到的是HDFS架构未找到。

java.io.IOException: No FileSystem for scheme: hdfs 

当我使用两个罐子时,我得到上述错误。

在servlet中的代码:

 Configuration conf = new Configuration(); 

    try { 
     System.out.println("keyword=" + keyWord); 
     conf.set("keyword", keyWord); 
     conf.set("fs.hdfs.impl", 
       org.apache.hadoop.fs.hdfs.DistributedFileSystem.class.getName() 
      ); 

     Job job = Job.getInstance(); 
     job.setJarByClass(HadoopServlet.class); 

     job.setJobName("Tomcat Log Error"); 
     FileInputFormat.addInputPath(job, new Path("hdfs://master:54310/keyword/pg20417.txt")); 
     FileOutputFormat.setOutputPath(job, new Path("hdfs://master:54310/tmp/output" + uuid)); 
     job.setMapperClass(TomcatLogErrorMapper.class); 
     job.setReducerClass(TomcatLogErrorReducer.class); 
     job.setOutputKeyClass(Text.class); 
     job.setOutputValueClass(Text.class); 
     System.exit(job.waitForCompletion(true) ? 0 : 1); 
    } 
    catch (Exception e) { 
      System.out.println("Error"); 
      e.printStackTrace(); 
    } 

任何帮助理解。

发现这个线程

A Servlet Container on top of Hadoop?

看起来像一个不能使用servlet来运行Hadoop作业。

+0

没有你设法解决这个问题?我面临同样的问题。 – 2016-06-01 09:08:23

回答

0

由于hdfs模式已经在hadoop-hdfs.jar中注册,因此您不能单独使用hadoop-core.jar。

它看起来像你的跑步servlet线程的上下文类加载器无法加载org.apache.hadoop.hdfs.DistributedFileSystem,你可以试试这个:

Thread.currentThread().setContextClassLoader(ClassLoader.getSystemClassLoader()); 
相关问题