简体   繁体   English

Hadoop:奇怪的ClassNotFoundException

[英]Hadoop: strange ClassNotFoundException

I am getting a classnotfound exception. 我得到一个classnotfound异常。 The class which is claimed to be not found does not exist, but the class name is set as the path to the list of input files for my map reduce jobs. 声称未找到的类不存在,但类名称被设置为我的map reduce作业的输入文件列表的路径。

INFO  server Running: /usr/lib/hadoop/bin/hadoop --config /var/run/cloudera-scm-agent/process/155-hue/JOBSUBD/hadoop-conf jar tmp.jar /user/hduser/datasets/ /user/hduser/tmp/job_20/ mongodb://slave15/db_8.job_20

Exception in thread "main" java.lang.ClassNotFoundException: /user/hduser/datasets/

at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:247)
at org.apache.hadoop.util.RunJar.main(Runjar.java:190)

As we can see, the /user/hduser/datasets/ is the path to the input files. 我们可以看到, /user/hduser/datasets/是输入文件的路径。 Why am I getting this error as ClassNotFoundException ? 为什么我将此错误作为ClassNotFoundException获取? Why does it see it as a class? 为什么它把它视为一个类?


I found my own error. 我发现了自己的错误。 I have a package structure. 我有一个包结构。 I need to specify my package information 我需要指定我的包信息

/usr/lib/hadoop/bin/hadoop 
    --config /var/run/cloudera-scm-agent/process/155-hue/JOBSUBD/hadoop-conf 
    jar tmp.jar org.myorg.tmp /user/hduser/datasets/ 
    /user/hduser/tmp/job_20/ mongodb://slave15/db_8.job_20

In my tool, there is no option for giving the package as argument to Java. 在我的工具中,没有选项可以将包作为Java的参数。 So I need to have no packaging. 所以我需要没有包装。 But then I am having the following error since the argument before this input file path is missing. 但是,由于缺少此输入文件路径之前的参数,因此出现以下错误。

My classes are directly in the tmp.jar in its root. 我的类直接在其根目录中的tmp.jar中。 I mean no org.myorg etc... 我的意思是没有org.myorg等......

SOLUTION: 解:

jar cmf [manifest_file] [jar_name.jar] -C [folder_of_classes] [path_for_jar_file]

it will merge the content of the manifest_file with the generated manifest file in the jar archive. 它会将manifest_file的内容与jar存档中生成的清单文件合并。 Include the following line in the manifest_file Main-Class: [Name_Of_Class] 在manifest_file Main-Class中包含以下行:[Name_Of_Class]

Whether or not there's a package hierarchy (and if there isn't, you've done Something Wrong) you still need to give it the name of the class containing main . 无论是否有包层次结构(如果没有,你做错了什么),你仍然需要给它包含main的类的名称。

For example, the docs have an example where the main class is org.myorg.WordCount . 例如, 文档中有一个主要类是org.myorg.WordCount的示例。 Even if WordCount was in the default package, it should be specified if the jar file doesn't include a main class in the manifest: 即使WordCount在默认包中,也应该指定jar文件是否在清单中不包含主类:

bin/hadoop jar /usr/joe/wordcount.jar WordCount /usr/joe/wordcount/input /usr/joe/wordcount/output

I'd assume you could also specify the main class in the manifest as with any jar; 我假设您还可以在清单中指定主类,就像任何jar一样; the class argument is shown as optional in those same docs. class参数在那些相同的文档中显示为可选。

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

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