nosuchmethoderror:org.apache.hadoop.io.retry.retryutils.getdefaultretrypolicy

dojqjjoe  于 2021-06-02  发布在  Hadoop
关注(0)|答案(2)|浏览(504)

以前我在中创建目录 hdfs 从java到 single node cluster 它运行得很平稳,但是当我创建集群多节点时,我得到了这个错误,我得到的stacktrace是这样的

Exception in thread "main" java.lang.NoSuchMethodError: org.apache.hadoop.io.retry.RetryUtils.getDefaultRetryPolicy(Lorg/apache/hadoop/conf/Configuration;Ljava/lang/String;ZLjava/lang/String;Ljava/lang/String;Ljava/lang/Class;)Lorg/apache/hadoop/io/retry/RetryPolicy;
    at org.apache.hadoop.hdfs.NameNodeProxies.createNNProxyWithClientProtocol(NameNodeProxies.java:410)
    at org.apache.hadoop.hdfs.NameNodeProxies.createNonHAProxy(NameNodeProxies.java:316)
    at org.apache.hadoop.hdfs.NameNodeProxies.createProxy(NameNodeProxies.java:178)
    at org.apache.hadoop.hdfs.DFSClient.<init>(DFSClient.java:665)
    at org.apache.hadoop.hdfs.DFSClient.<init>(DFSClient.java:601)
    at org.apache.hadoop.hdfs.DistributedFileSystem.initialize(DistributedFileSystem.java:148)
    at org.apache.hadoop.fs.FileSystem.createFileSystem(FileSystem.java:2811)
    at org.apache.hadoop.fs.FileSystem.access$200(FileSystem.java:100)
    at org.apache.hadoop.fs.FileSystem$Cache.getInternal(FileSystem.java:2848)
    at org.apache.hadoop.fs.FileSystem$Cache.get(FileSystem.java:2830)
    at org.apache.hadoop.fs.FileSystem.get(FileSystem.java:389)
    at CreateDirectory.main(CreateDirectory.java:44)

下面是createdirectory类

public static void main(String[] args) throws SQLException, ClassNotFoundException {
        String hdfsUri = "hdfs://localhost:9000/";
       //String dirName = args[0];
        String dirName=null;
      // String filename = args[1];
        String filename;

        if(args.length<=0) dirName = "ekbana"; filename = "text.csv";

        URL url = null;
        BufferedReader in = null;
        FileSystem hdfs = null;
        FSDataOutputStream outStream = null;
        HttpURLConnection conn = null;
        List<Map<String, String>> flatJson;
        Configuration con = new Configuration();
        try {
            url = new URL("http://crm.bigmart.com.np:81/export/export-sales-data.php?sdate=2016-12-01&edate=2016-12-02&key=jdhcvuicx8ruqe9djskjf90ueddishr0uy8v9hbjncvuw0er8idsnv");
        } catch (MalformedURLException ex) {
        }

        try {
            con.set("fs.hdfs.impl", org.apache.hadoop.hdfs.DistributedFileSystem.class.getName());
            con.set("fs.file.impl", org.apache.hadoop.fs.LocalFileSystem.class.getName());
            hdfs = FileSystem.get(URI.create(hdfsUri), con); // this is line 44 
        } catch (IOException e) {
            e.printStackTrace();
        }

        try {
            System.out.println(hdfs.mkdirs(new Path(hdfsUri + "/" + dirName)));
        } catch (IOException e) {
            e.printStackTrace();
        }

很多网站上的解决方案都说我需要hadoop common,我已经有了它,但是我仍然会遇到这个错误。我怀疑重试策略是否与我的设置相关,如果不是,那么为什么会出现这个错误?

ix0qys7i

ix0qys7i1#

添加maven依赖项有助于:

<dependency>
   <groupId>org.apache.hadoop</groupId>
   <artifactId>hadoop-hdfs</artifactId>
   <version>2.8.1</version>
</dependency>
7gs2gvoe

7gs2gvoe2#

我非常赞同尤利娅的回答,这使我理解并解决了我所面临的问题。你可以按照她的建议或补充:

/path/to/hadoop-client/client/hadoop-hdfs-client-<version_number>.jar

以使hadoop hdfs客户机jar在运行时包含在内。

相关问题