在eclipse wordcount程序中找不到类异常

f87krz0w  于 2021-06-03  发布在  Hadoop
关注(0)|答案(1)|浏览(261)

我正在运行一个来自eclipse的单词计数程序,它说找不到类。我导出了和jar文件相同的程序,并从命令行执行,运行良好。
这是错误堆栈跟踪

14/02/14 23:46:16 WARN mapred.JobClient: Use GenericOptionsParser for parsing the arguments. Applications should implement Tool for the same.
    14/02/14 23:46:16 WARN mapred.JobClient: No job jar file set.  User classes may not be found. See JobConf(Class) or JobConf#setJar(String).
    14/02/14 23:46:16 INFO input.FileInputFormat: Total input paths to process : 1
    14/02/14 23:46:16 WARN util.NativeCodeLoader: Unable to load native-hadoop library for your platform... using builtin-java classes where applicable
    14/02/14 23:46:16 WARN snappy.LoadSnappy: Snappy native library not loaded
    14/02/14 23:46:17 INFO mapred.JobClient: Running job: job_201402142205_0013
    14/02/14 23:46:18 INFO mapred.JobClient:  map 0% reduce 0%
    14/02/14 23:46:28 INFO mapred.JobClient: Task Id : attempt_201402142205_0013_m_000000_0, Status : FAILED
    java.lang.RuntimeException: java.lang.ClassNotFoundException: hadoop.wc.WordCount$TokenCounterMapper
        at org.apache.hadoop.conf.Configuration.getClass(Configuration.java:857)
        at org.apache.hadoop.mapreduce.JobContext.getMapperClass(JobContext.java:199)
        at org.apache.hadoop.mapred.MapTask.runNewMapper(MapTask.java:718)
        at org.apache.hadoop.mapred.MapTask.run(MapTask.java:364)
        at org.apache.hadoop.mapred.Child$4.run(Child.java:255)
        at java.security.AccessController.doPrivileged(Native Method)
        at javax.security.auth.Subject.doAs(Subject.java:394)
        at org.apache.hadoop.security.UserGroupInformation.doAs(UserGroupInformation.java:1190)
        at org.apache.hadoop.mapred.Child.main(Child.java:249)
    Caused by: java.lang.ClassNotFoundException: hadoop.wc.WordCount$TokenCounterMapper
        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 sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:247)
        at java.lang.Class.forName0(Native Method)
        at java.lang.Class.forName(Class.java:249)
        at org.apache.hadoop.conf.Configuration.getClassByName(Configuration.java:810)
        at org.apache.hadoop.conf.Configuration.getClass(Configuration.java:855)
        ... 8 more

attempt_201402142205_0013_m_000000_0: 2014-02-14 23:46:20.815 java[8633:1003] Unable to load realm info from SCDynamicStore
14/02/14 23:46:28 INFO mapred.JobClient: Task Id : attempt_201402142205_0013_m_000001_0, Status : FAILED

作业配置

Job job = new Job(conf, "WordCount");
  job.setJarByClass(WordCount.class);
  job.setMapperClass(TokenCounterMapper.class);
  job.setReducerClass(TokenCounterReducer.class);
  job.setNumReduceTasks(2);
  job.setOutputKeyClass(Text.class);
  job.setOutputValueClass(IntWritable.class);

谢谢你的帮助。

3df52oht

3df52oht1#

如果您试图直接从eclipse运行作业,那么首先需要将项目导出为可运行的jar。你可以把这个jar放在你机器的任何地方。您只需要在驱动程序类的主方法中指定jar的位置,如下所示:
conf.set(“mapred.jar”,“d:\mapred\u example.jar”);
希望这有帮助!

相关问题