Java | Jar包操作HDFS系统问题

  • 内容
  • 相关

Exception in thread "main" org.apache.hadoop.fs.UnsupportedFileSystemException: No FileSystem for sc

问题描述

java代码,打包到虚拟机,希望运行后在HDFS创建一个文件夹 /java。代码如下:

 

public class HdfsStart {
    private FileSystem fs;
    // 初始化
    public void init() throws URISyntaxException, IOException, InterruptedException {
        Configuration conf = new Configuration();
        fs = FileSystem.get(new URI("hdfs://localhost:9000"),conf);
    }
 
    // 创建文件夹
    public void testMkdir() throws IOException {
        boolean flag = fs.mkdirs(new Path("/java"));
        System.out.println(flag);
    }
 
    /**
     * 创建成功则会输出true
     * @param args
     * @throws InterruptedException
     * @throws IOException
     * @throws URISyntaxException
     */
    public static void main(String[] args) throws InterruptedException, IOException, URISyntaxException {
        HdfsStart hdfsStart = new HdfsStart();
        hdfsStart.init();
        hdfsStart.testMkdir();
    }
 
}

 

当然,虚拟机系统上也启动了hdfs服务(sbin/start-dfs.sh

打包上传后运行方法为:

$ java  -jar  hadoop-demo.jar


报错如下: 

Exception in thread "main" org.apache.hadoop.fs.UnsupportedFileSystemException: No FileSystem for scheme "hdfs"
   at org.apache.hadoop.fs.FileSystem.getFileSystemClass(FileSystem.java:3281)
   at org.apache.hadoop.fs.FileSystem.createFileSystem(FileSystem.java:3301)
   at org.apache.hadoop.fs.FileSystem.access$200(FileSystem.java:124)
   at org.apache.hadoop.fs.FileSystem$Cache.getInternal(FileSystem.java:3352)
   at org.apache.hadoop.fs.FileSystem$Cache.get(FileSystem.java:3320)
   at org.apache.hadoop.fs.FileSystem.get(FileSystem.java:479)
   at cn.smileyan.hadoop.hdfs.HdfsStart.init(HdfsStart.java:20)
   at cn.smileyan.hadoop.hdfs.HdfsStart.main(HdfsStart.java:38)

 

解决方法

运行时改用命令如下:

$ bin/hadoop jar hadoop-demo.jar

 您阅读这篇文章共花了:

上一篇:Java | Intellij IDEA 添加jar包的三种方式

下一篇:Hadoop | hbase shell命令行下backspace键无效解决办法

本文标签:    

版权声明:本文依据CC-BY-NC-SA 3.0协议发布,若无特殊注明,本文皆为《fishyoung》原创,转载请保留文章出处。

本文链接:Java | Jar包操作HDFS系统问题 - http://www.fishyoung.com/post-287.html