簡體   English   中英

hadoop jar命令指向本地文件系統

[英]hadoop jar command points to local filesystem

我有一個有效的jar,它在運行相同版本的hadoop的另一個系統上完美運行,即具有相同設置的hadoop-1.2.1。

我能夠將jar文件放在hdfs文件系統中並創建輸入,輸出目錄。

但是當我使用命令'hadoop jar HelloWorld.jar classname(main method)輸出'時,它會拋出'Invalid jar'錯誤。 在長時間搜索可能的解決方案后,我發現該命令正在本地文件系統中搜索jar而不是在hdfs中搜索。

即使我嘗試將方案添加到命令中:hadoop jar hdfs://HelloWorld.jar classname(main方法)輸入輸出

有什么可能的解決方案?

PS:當我的PWD是/home/user/hadoop-1.2.1時,我能夠使用'hadoop jar'運行hadoop-examples-1.2.1.jar,這是我本地的文件系統

hadoop jar只運行你可以在本地訪問的jar文件1 只是為了好奇 - 這是在hadoop jar命令中查找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版本都是如此。 您的結果可能會有所不

這個代碼在我的$ HADOOP_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分布可以做到這一點。

可能,現在回答這個討論為時已晚,雖然我沒有看到任何可接受的答案,所以想到回答這個問題。 今天,我遇到了同樣的問題,經過幾個小時的努力,我能夠解決它。 我找到了“不是一個有效的罐子”問題的兩個原因。

  1. 當我們從HDFS引用Jar時,它會出現此錯誤。 我在本地文件系統中更改了對jar文件的引用,並且它正常工作。 我的理解是,不需要將Jar文件放入HDFS。 'hadoop jar HelloWorld.jar(參考你的本地文件系統)classname(main方法)輸入輸出'

  2. 在創建Jar文件並在創建Jar文件時定義Main-Class時,您不需要在命令中定義classname。

'hadoop jar HelloWorld.jar classname(主方法 - 如果你已經在創建jar文件時定義了Main-Class,那么這不是必需的)輸入輸出'

以下將是命令:'hadoop jar HelloWorld.jar輸入輸出'

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM