hdfs java jar_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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值