简体   繁体   English

如何从HDFS FileSystem执行hadoop jar?

[英]how to execute hadoop jar from HDFS FileSystem?

I'm always executing job from local File system as following 我总是从本地文件系统执行作业,如下所示

hadoop jar /home/usr/jar/myjar.jar com.test.TestMain 

How can I execute same command but myjar.jar will be in hdfs ? 我如何执行相同的命令,但myjar.jar将位于hdfs中?

Something like 就像是

hadoop jar hdfs:///home/usr/jar/myjar.jar com.test.TestMain 

But of course this doesn't work... 但是这当然行不通...

hadoop fs -copyToLocal hdfs:///home/usr/jar/myjar.jar /tmp/myjar.jar && hadoop jar /tmp/myjar.jar com.test.TestMain 

Looking at bin/hadoop script for Hadoop, for executing a jar file it uses this condition -- 查看Hadoop的bin/hadoop脚本,为了执行jar文件,它使用了以下条件-

elif [ "$COMMAND" = "jar" ] ; then
  CLASS=org.apache.hadoop.util.RunJar

This says it uses RunJar class to execute the jar. 这表示它使用RunJar类执行jar。 If you see the RunJar class, the arguments supported are -- 如果看到RunJar类,则支持的参数是-

RunJar jarFile [mainClass] args...

where, jarFile is accessed using the following code inside RunJar Class-- 在其中,使用RunJar类中的以下代码访问jarFile-

int firstArg = 0;
String fileName = args[firstArg++];
File file = new File(fileName);

Hence, fileName points to jarFile , so fileName in my view cannot be a HDFS path as seen above, unless you are somehow able to mount the HDFS in your file system, so that it becomes accessible by the java File class. 因此, fileName指向jarFile ,因此在我看来, fileName不能是如上所述的HDFS路径,除非您能够以某种方式将HDFS挂载到文件系统中,以便java File类可以访问它。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM