【问题标题】:Error running Jar file in Hadoop's MapReduce program在 Hadoop 的 MapReduce 程序中运行 Jar 文件时出错
【发布时间】:2013-09-19 03:12:46
【问题描述】:

我正在尝试将我的代码编译成一个 JAR 文件,以便与 Hadoop 的 MapReduce 一起使用。我的主类是VectorMaker.java,director结构如下。

RandomForestVectors
 /bin
 /lib
   /hadoop-core-1.2.0.jar
   /mahout-core-0.7.jar
   /mahout-math-0.7.jar
   /opencsv-2.3.jar
 /VectorMaker.java

这些是我用来制作 JAR 文件的命令。

   javac -classpath "./lib/*" -d ./bin ./VectorMaker.java
   jar cf VectorMaker.jar -C "./bin/" . &

这是我用来尝试将我的 JAR 文件作为 Hadoop MapReduce 程序运行的命令。

hadoop jar VectorMaker.jar VectorMaker user/starmine/AlphaDefault/mahout/random_forest/prevectors  /user/starmine/AlphaDefault/mahout/random_forest/test1


Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/mahout/math/VectorWritable
    at VectorMaker.main(VectorMaker.java:67)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at org.apache.hadoop.util.RunJar.main(RunJar.java:208)
Caused by: java.lang.ClassNotFoundException: org.apache.mahout.math.VectorWritable
    at java.net.URLClassLoader$1.run(URLClassLoader.java:202)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:247)

我知道我需要以某种方式使我的 JAR 文件包含我的所有依赖项,但我不确定如何。

【问题讨论】:

    标签: java hadoop jar mapreduce


    【解决方案1】:

    确保类路径中包含所有依赖项,包括所有 Mahout 库。或者,您可以在编译程序时通过 -classpath 指定路径。

    javac -classpath -classpath $MAHOUT_HOME/lib/*

    【讨论】:

    • 很抱歉,您的意思是 javac -classpath $MAHOUT_HOME/lib/。如果我只是引用我的 lib 文件夹中的 jar 文件,又名 javac -classpath "./lib/*" -d ./bin ./VectorMaker.java,为什么它不起作用
    • 它应该可以工作。我只是想确保您也添加了驯象罐。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-08-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多