简体   繁体   English

运行hadoop jar时发生ClassNotFoundException

[英]ClassNotFoundException when running hadoop jar

I'm attempting to run a MapReduce job from a jar file and keep getting a ClassNotFoundException error. 我正在尝试从jar文件运行MapReduce作业,并不断收到ClassNotFoundException错误。 I'm running Hadoop 1.2.1 on a Centos 6 virtual machine. 我在Centos 6虚拟机上运行Hadoop 1.2.1。

First I compiled the file exercise.java (and class) into a jar file exercise.jar using the following shell script compile.sh : 首先,我使用以下shell脚本compile.sh将文件exercise.java (和类)编译为一个jar文件exercise.jar

#!/bin/bash

javac -classpath /pathto/hadoop-common-1.2.1.jar:\
/pathto/hadoop-core-1.2.1.jar /pathto/exercise.java

jar cvf exercise.jar /pathto/*.class

This runs fine and the jar completes successfully. 运行正常,罐子成功完成。 I then attempt to run the actual MapReduce job using shell script exec.sh : 然后,我尝试使用shell脚本exec.sh运行实际的MapReduce作业:

#!/bin/bash

export CLASSPATH=$CLASSPATH:/pathto/hadoop-common-1.2.1.jar:\
/pathto/hadoop-core-1.2.1.jar:/pathto/exercise.class

hadoop jar exercise.jar exercise /data/input/inputfile.txt /data/output

This trows the ClassNotFoundException error : 这引发ClassNotFoundException错误:

Exception in thread "main" java.lang.ClassNotFoundException: exercise
    at java.net.URLClassLoader$1.run(URLClassLoader.java:366)
    at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:425)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:358)
    at java.lang.Class.forName0(Native Method)
    at java.lang.Class.forName(Class.java:274)
    at org.apache.hadoop.util.RunJar.main(RunJar.java:153) 

I realize the explicit path names might not be necessary but I've been a little desperate to double check everything. 我意识到显式路径名可能不是必需的,但是我一直很想再次检查所有内容。 I've confirmed that in my exercise.java file exercise.class is in the job configuration via job.setJarByClass(exercise.class); 我已经确认,在我的exercise.java文件中, exercise.class通过job.setJarByClass(exercise.class);在作业配置中job.setJarByClass(exercise.class); and confirmed exercise.class is contained in exercise.jar . 并且已确认的exercise.class包含在exercise.jar Can't seem to figure it out. 似乎无法弄清楚。

UPDATE The exec.sh script with the full path of exercise.class . 更新 exec.sh脚本,其中包含exercise.class的完整路径。 It's stored in my Eclipse project directory: 它存储在我的Eclipse项目目录中:

#!/bin/bash

export CLASSPATH=$CLASSPATH:/pathto/hadoop-common-1.2.1.jar:\
/pathto/hadoop-core-1.2.1.jar:/home/username/workspace/MVN_Hadoop/src/main/java.com.amend.hadoop.MapReduce/*

hadoop jar \
exercise.jar \
/home/username/workspace/MVN_Hadoop/src/main/java.com.amend.hadoop.MapReduce/exercise \
/data/input/inputfile.txt \
/data/output

When I actually try and run the exec.sh script using the explicitly written out path names, I also get a completely different set of errors: 当我实际尝试使用显式写出的路径名运行exec.sh脚本时,我还得到了一套完全不同的错误:

Exception in thread "main" java.lang.ClassNotFoundException: /home/hdadmin/workspace/MVN_Hadoop/src/main/java/come/amend/hadoop/MapReduce/exercise
    at java.lang.Class.forName0(Native Method)
    at java.lang.Class.forName(Class.java:274)
    at org.apache.hadoop.util.RunJar.main(RunJar.java:153) 

I could see this possible errors. 我可以看到这种可能的错误。 From the Hadoop jar exercise.jar exercise /data/input/inputfile.txt /data/output please specify the full path of the exercise class. Hadoop jarexercise.jar练习/data/input/inputfile.txt / data / output中,请指定练习类的完整路径。 Ie org.name.package.exercise if exists. org.name.package.exercise(如果存在)。 To cross check open the jar file and check the location of exercise.class location. 要交叉检查,请打开jar文件并检查exercise.class位置。 To continue, Hadoop doesn't expect jars to be included within the jars, since the path of Hadoop is set globally. 继续,Hadoop不希望将jar包含在jar中,因为Hadoop的路径是全局设置的。

NEW: See, the following path is some thing weird. 新:请看,以下路径有些奇怪。 "/home/hdadmin/workspace/MVN_Hadoop/src/main/java/come/amend/hadoop/MapReduce/exercise" “ / home / hdadmin / workspace / MVN_Hadoop / src / main / java / come / amend / hadoop / MapReduce / exercise”

If you are running using your jar, how could a class path be so specific, instead of jar path. 如果您正在使用jar运行,那么类路径怎么会如此具体,而不是jar路径。 It could only be "come/amend/hadoop/MapReduce/exercise" this. 它只能是“ come / amend / hadoop / MapReduce / exercise”。

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

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