Hadoop 从 Hadoop 节点的本地文件系统访问 3rd 方库
Hadoop accessing 3rd party libraries from local file system of a Hadoop node
我在 /home/ubuntu/libs/javacv-0.9.jar
的所有 Hadoop 节点上都有一个 jar 文件,还有一些其他的 jar 文件。
当我的 MapReduce 应用程序在 Hadoop 节点上执行时,我收到此异常
java.io.FileNotFoundException: File does not exist hdfs://192.168.0.18:50000/home/ubuntu/libs/javacv-0.9.jar
如何解决这个异常?我在 Hadoop 中的 jar 运行 如何从 Hadoop 节点的本地文件系统访问第 3 方库?
您需要将文件复制到 HDFS 而不是本地文件系统。
要将文件复制到 HDFS,您需要使用:
hadoop fs -put localfile hdfsPath
其他选项是将文件路径更改为:
file:///home/ubuntu/libs/javacv-0.9.jar
要将 jar 文件添加到类路径,请查看 DistributedCache:
DistributedCache.addFileToClassPath(new Path("file:///home/ubuntu/libs/javacv-0.9.jar"), job);
您可能需要遍历该目录中的所有 jar 文件。
另一种选择是使用 distributed cache 的 addFileToClassPath(new Path("/myapp/mylib.jar"), job);
提交应添加到映射器和缩减器任务的 class 路径的 Jar 文件。
Note: Make sure you copy the jar file to HDFS first.
您甚至可以使用 hadoop 命令行参数 -libjars <jar_file>
.
将 jar 文件添加到 class 路径
Note: Make sure your MapReduce application implements ToolRunner to allow -libjars
option from command line.
我在 /home/ubuntu/libs/javacv-0.9.jar
的所有 Hadoop 节点上都有一个 jar 文件,还有一些其他的 jar 文件。
当我的 MapReduce 应用程序在 Hadoop 节点上执行时,我收到此异常
java.io.FileNotFoundException: File does not exist hdfs://192.168.0.18:50000/home/ubuntu/libs/javacv-0.9.jar
如何解决这个异常?我在 Hadoop 中的 jar 运行 如何从 Hadoop 节点的本地文件系统访问第 3 方库?
您需要将文件复制到 HDFS 而不是本地文件系统。
要将文件复制到 HDFS,您需要使用:
hadoop fs -put localfile hdfsPath
其他选项是将文件路径更改为:
file:///home/ubuntu/libs/javacv-0.9.jar
要将 jar 文件添加到类路径,请查看 DistributedCache:
DistributedCache.addFileToClassPath(new Path("file:///home/ubuntu/libs/javacv-0.9.jar"), job);
您可能需要遍历该目录中的所有 jar 文件。
另一种选择是使用 distributed cache 的 addFileToClassPath(new Path("/myapp/mylib.jar"), job);
提交应添加到映射器和缩减器任务的 class 路径的 Jar 文件。
Note: Make sure you copy the jar file to HDFS first.
您甚至可以使用 hadoop 命令行参数 -libjars <jar_file>
.
Note: Make sure your MapReduce application implements ToolRunner to allow
-libjars
option from command line.