hadoopjar命令指向本地文件系统

mu0hgdu0  于 2021-06-03  发布在  Hadoop
关注(0)|答案(3)|浏览(366)

我有一个有效的jar,它在另一个运行相同版本hadoop的系统上运行得非常好,即hadoop-1.2.1,具有相同的设置。
我能够将jar文件放在hdfs文件系统中,并创建输入、输出目录。
但是当我使用命令'hadoop jar helloworld.jar classname(main method)input output'时,它抛出'invalid jar'错误。在搜索了很长一段时间可能的解决方案之后,我发现这个命令是在本地文件系统中搜索jar,而不是在hdfs中搜索。
甚至我也尝试将scheme添加到命令中:hadoopjarhdfs://helloworld.jar classname(主方法)输入输出
有什么可能的解决办法?
p、 s:当我的pwd是/home/user/hadoop-1.2.1时,我可以使用'hadoop-jar'运行hadoop-examples-1.2.1.jar,它在我的本地文件系统中

siotufzp

siotufzp1#

hadoop jar 只运行可以访问locally1的jar文件。只是出于好奇-以下是在 hadoop jar 命令。

public static void main(String[] args) throws Throwable {
  String usage = "RunJar jarFile [mainClass] args...";

  if (args.length < 1) {
    System.err.println(usage);
    System.exit(-1);
  }

  int firstArg = 0;
  String fileName = args[firstArg++];
  File file = new File(fileName);
  if (!file.exists() || !file.isFile()) {
    System.err.println("Not a valid JAR: " + file.getCanonicalPath());
    System.exit(-1);
  }
  ...
}

1我遇到的每个hadoop版本都是这样。你的结果可能会有所不同。

8wigbo56

8wigbo562#

也许,现在回答这个讨论已经太迟了,虽然我没有看到任何公认的答案,所以我想回答这个问题。今天,我遇到了同样的问题,经过几个小时的努力,终于解决了。我发现“不是一个有效的jar”的问题有两个原因。
当我们从hdfs中引用jar时,它给出了这个错误。我在本地文件系统中更改了对jar文件的引用,它工作正常。我的理解是,不需要将jar文件放在hdfs中hadoop jar helloworld.jar(从本地文件系统引用)classname(main方法)input output'
创建jar文件并在创建jar文件时定义main类时,不需要在命令中定义classname。
'hadoop jar helloworld.jar classname(main方法如果在创建jar文件时已经定义了main class,则不需要此方法)input output'
下面是命令:“hadoop jar helloworld.jar input output”

klh5stk1

klh5stk13#

这段代码在我的$hadoop\u home/bin/hadoop脚本中

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

它指向runjar类。
在runjar里你有这个,

/**Run a Hadoop job jar.  If the main class is not in the jar's manifest,
   * then it must be provided on the command line. */
  public static void main(String[] args) throws Throwable {
    String usage = "RunJar jarFile [mainClass] args...";

    if (args.length < 1) {
      System.err.println(usage);
      System.exit(-1);
    }

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

    JarFile jarFile;
    try {
      jarFile = new JarFile(fileName);
    } catch(IOException io) {
      throw new IOException("Error opening job jar: " + fileName)
        .initCause(io);
    }

    ------ Other code -------
}

所以,我不确定 File file = new File(fileName); 实际上可以指向hdfs路径吗?
也许hadoop的mapr发行版可以做到这一点。

相关问题