hadoop 2.6.0浏览文件系统java

w51jfk4q  于 2021-05-30  发布在  Hadoop
关注(0)|答案(1)|浏览(331)

我已经在centos 6.6上安装了一个基本的hadoop集群,并想编写一些基本程序(浏览文件系统、删除/添加文件等),但我很难让最基本的应用程序正常工作。
当运行一些基本代码以将目录的内容列出到控制台时,我遇到以下错误:

  1. Exception in thread "main" java.lang.NoSuchMethodError: org.apache.hadoop.ipc.RPC.getProxy(Ljava/lang/Class;JLjava/net/InetSocketAddress;Lorg/apache/hadoop/security/UserGroupInformation;Lorg/apache/hadoop/conf/Configuration;Ljavax/net/SocketFactory;ILorg/apache/hadoop/io/retry/RetryPolicy;Z)Lorg/apache/hadoop/ipc/VersionedProtocol;
  2. at org.apache.hadoop.hdfs.DFSClient.createRPCNamenode(DFSClient.java:135)
  3. at org.apache.hadoop.hdfs.DFSClient.<init>(DFSClient.java:280)
  4. at org.apache.hadoop.hdfs.DFSClient.<init>(DFSClient.java:245)
  5. at org.apache.hadoop.hdfs.DistributedFileSystem.initialize(DistributedFileSystem.java:100)
  6. at mapreducetest.MapreduceTest.App.main(App.java:36)

我的pom.xml依赖项

  1. <dependencies>
  2. <dependency>
  3. <groupId>org.apache.hadoop</groupId>
  4. <artifactId>hadoop-common</artifactId>
  5. <version>2.6.0</version>
  6. </dependency>
  7. <dependency>
  8. <groupId>org.apache.hadoop</groupId>
  9. <artifactId>hadoop-core</artifactId>
  10. <version>1.2.1</version>
  11. </dependency>
  12. </dependencies>

代码:

  1. import java.io.IOException;
  2. import java.net.URI;
  3. import java.net.URISyntaxException;
  4. import org.apache.hadoop.conf.Configuration;
  5. import org.apache.hadoop.fs.FileStatus;
  6. import org.apache.hadoop.fs.FileSystem;
  7. import org.apache.hadoop.fs.Path;
  8. import org.apache.hadoop.hdfs.DistributedFileSystem;
  9. public class App
  10. {
  11. public static void main( String[] args ) throws IOException, URISyntaxException
  12. {
  13. Configuration conf = new Configuration();
  14. FileSystem fs = new DistributedFileSystem();
  15. fs.initialize(new URI("hdfs://localhost:9000/"), conf);
  16. for (FileStatus f :fs.listStatus(new Path("/")))
  17. {
  18. System.out.println(f.getPath().getName());
  19. }
  20. fs.close();
  21. }
  22. }

调用fs.initialize()后引发错误。我真的不知道这里有什么问题。我是否缺少依赖项?他们的版本不对吗?

qacovj5a

qacovj5a1#

我通过调用“java-jarapp.jar”来运行这个程序。。。。我应该使用hadoopjarapp.jar。
当我正确运行它时,它按预期工作。

相关问题