通过分布式缓存hadoop添加jar

use*_*241 2 hadoop

我使用Disributed Cache将.jar文件添加到类路径:

DistributedCache.addFileToClassPath(new Path("binary/tools.jar"), job.getConfiguration());
Run Code Online (Sandbox Code Playgroud)

我不确定addFileToClassPath()是否是用于将.jar文件添加到类路径的正确API.当我尝试从映射器中检索类路径时,我看不到添加的jar.类路径包含作业的工作目录(jobcache dir),但不包括通过分布式缓存分发的jar.

Properties prop = System.getProperties();
System.out.println("The classpath is: " + prop.getProperty("java.class.path", null));
Run Code Online (Sandbox Code Playgroud)

我也尝试了addArchiveToClassPath()..它没有工作..

我错过了什么吗?

谢谢,

use*_*241 7

问题出在路径上.addFileToClassPath()addArchiveToClassPath()仅采用绝对路径作为输入.binary/tools.jar是相对的,因此不起作用.我需要指定路径,因为/user/<username>/binary/tools.jar.. 它工作正常.甚至hdfs://<hostname>:port/user/..失败了.

谢谢你们..