我正在运行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);
感谢您的帮助。
答案 0 :(得分:2)
如果您尝试直接从eclipse运行作业,则需要先将项目导出为可运行的jar。您可以将此jar放在机器的任何位置。您只需要在驱动程序类的main方法中指定jar的位置,如下所示:
<强> conf.set( “mapred.jar”, “d:\ mapred_example.jar”); 强>
希望这有帮助!