2015-04-04 83 views

回答

1

這是如何編寫自定義類加載器的。代碼是用scala編寫的。你可以把它轉換成java。

class HdfsClassLoaderclassLoader(classLoader: ClassLoader) extends URLClassLoader(Array.ofDim[URL](0), classLoader) { 

    def addJarToClasspath(jarName: String) { 
     synchronized { 
      var conf = new Configuration 
      val fileSystem = FileSystem.get(conf) 
      val path = new Path(jarName); 
      if (!fileSystem.exists(path)) { 
       println("File does not exists") 
      } 
      val uriPath = path.toUri() 
      val urlPath = uriPath.toURL() 
      println(urlPath.getFile) 
      addURL(urlPath) 
     } 
    } 
} 
+0

Thanks Hafiz Mujadid – 2015-04-04 10:08:29

相關問題