JAVA 連接HDFS錯誤 Class org.apache.hadoop.hdfs.DistributedFileSystem not found


經過查看配置類Configration源代碼發現,類加載器會使用當前程序默認的Classloader

    public Configuration(boolean loadDefaults) {
        this.quietmode = true;
        this.allowNullValueProperties = false;
        this.resources = new ArrayList();
        this.finalParameters = Collections.newSetFromMap(new ConcurrentHashMap());
        this.loadDefaults = true;
        this.classLoader = Thread.currentThread().getContextClassLoader();
        if (this.classLoader == null) {
            this.classLoader = Configuration.class.getClassLoader();
        }

        this.loadDefaults = loadDefaults;
        this.updatingResource = new ConcurrentHashMap();
        Class var2 = Configuration.class;
        synchronized(Configuration.class) {
            REGISTRY.put(this, (Object)null);
        }
    }

  而我在kettle開發時使用的是插件形式,加載類時讀取了kettle默認的根目錄,導致無法加載插件的hdfs相關類。

  解決方式:初始化定義自己的classloader:

    Configuration hdfsConf = new Configuration();
    hdfsConf.setClassLoader(this.getClass().getClassLoader());

  

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM