hadoop wordCount eclipse执行提示ClassNotFoundException

hanwesley 2013-05-16
package com.wesley.hadoop;


import java.io.IOException;
import java.util.StringTokenizer;

import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.io.IntWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Job;
import org.apache.hadoop.mapreduce.Mapper;
import org.apache.hadoop.mapreduce.Reducer;
import org.apache.hadoop.mapreduce.lib.input.FileInputFormat;
import org.apache.hadoop.mapreduce.lib.output.FileOutputFormat;
import org.apache.hadoop.util.GenericOptionsParser;

public class WordCount {

	  public static class TokenizerMapper 
	       extends Mapper<Object, Text, Text, IntWritable>{
	    
	    private final static IntWritable one = new IntWritable(1);
	    private Text word = new Text();
	      
	    public void map(Object key, Text value, Context context
	                    ) throws IOException, InterruptedException {
	      StringTokenizer itr = new StringTokenizer(value.toString());
	      while (itr.hasMoreTokens()) {
	        word.set(itr.nextToken());
	        context.write(word, one);
	      }	
	    }
	  }
	  
	  public static class IntSumReducer 
	       extends Reducer<Text,IntWritable,Text,IntWritable> {
	    private IntWritable result = new IntWritable();

	    public void reduce(Text key, Iterable<IntWritable> values, 
	                       Context context
	                       ) throws IOException, InterruptedException {
	      int sum = 0;
	      for (IntWritable val : values) {
	        sum += val.get();
	      }
	      result.set(sum);
	      context.write(key, result);
	    }
	  }

	  public static void main(String[] args) throws Exception {
		Configuration  conf = new Configuration ();
	    conf.set("mapred.job.tracker", "9.248.69.79:9001"); 
	    conf.set("fs.default.name", "hdfs://9.248.69.79:9000"); 
	    conf.set("hadoop.job.ugi", "hadoop"); 
	    String[] otherArgs = new GenericOptionsParser(conf, args).getRemainingArgs();
	    if (otherArgs.length != 2) {
	      System.err.println("Usage: wordcount <in> <out>");
	      System.exit(2);
	    }
	    Job job = new Job(conf, "word count");
	    job.setJarByClass(WordCount.class);
	    job.setMapperClass(TokenizerMapper.class);
	    job.setCombinerClass(IntSumReducer.class);
	    job.setReducerClass(IntSumReducer.class);
	    job.setOutputKeyClass(Text.class);
	    job.setOutputValueClass(IntWritable.class);
	    FileInputFormat.addInputPath(job, new Path(otherArgs[0]));
	    FileOutputFormat.setOutputPath(job, new Path(otherArgs[1]));
	    System.exit(job.waitForCompletion(true) ? 0 : 1);
	    
	    
	    
	  }
	}


hadoop 1.0.4 可以连上HDSF,但是执行Eclipse就是不行。总是提示ClassNotFound


13/05/16 14:59:42 WARN mapred.JobClient: No job jar file set.  User classes may not be found. See JobConf(Class) or JobConf#setJar(String).
13/05/16 14:59:43 INFO input.FileInputFormat: Total input paths to process : 2
13/05/16 14:59:43 WARN util.NativeCodeLoader: Unable to load native-hadoop library for your platform... using builtin-java classes where applicable
13/05/16 14:59:43 WARN snappy.LoadSnappy: Snappy native library not loaded
13/05/16 14:59:44 INFO mapred.JobClient: Running job: job_201305162129_0001
13/05/16 14:59:45 INFO mapred.JobClient:  map 0% reduce 0%
13/05/16 15:00:05 INFO mapred.JobClient: Task Id : attempt_201305162129_0001_m_000000_0, Status : FAILED
java.lang.RuntimeException: java.lang.ClassNotFoundException: com.wesley.hadoop.WordCount$TokenizerMapper
at org.apache.hadoop.conf.Configuration.getClass(Configuration.java:867)
at org.apache.hadoop.mapreduce.JobContext.getMapperClass(JobContext.java:199)
at org.apache.hadoop.mapred.MapTask.runNewMapper(MapTask.java:719)
at org.apache.hadoop.mapred.MapTask.run(MapTask.java:370)
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:396)
at org.apache.hadoop.security.UserGroupInformation.doAs(UserGroupInformation.java:1121)
at org.apache.hadoop.mapred.Child.main(Child.java:249)
Caused by: java.lang.ClassNotFoundException: com.wesley.hadoop.WordCount$TokenizerMapper
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:820)
at org.apache.hadoop.conf.Configuration.getClass(Configuration.java:865)
... 8 more

13/05/16 15:00:08 WARN mapred.JobClient: Error reading task outputhadoop-master
13/05/16 15:00:08 WARN mapred.JobClient: Error reading task outputhadoop-master
13/05/16 15:00:08 INFO mapred.JobClient: Task Id : attempt_201305162129_0001_m_000001_0, Status : FAILED
java.lang.RuntimeException: java.lang.ClassNotFoundException: com.wesley.hadoop.WordCount$TokenizerMapper
at org.apache.hadoop.conf.Configuration.getClass(Configuration.java:867)
at org.apache.hadoop.mapreduce.JobContext.getMapperClass(JobContext.java:199)
at org.apache.hadoop.mapred.MapTask.runNewMapper(MapTask.java:719)
at org.apache.hadoop.mapred.MapTask.run(MapTask.java:370)
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:396)
at org.apache.hadoop.security.UserGroupInformation.doAs(UserGroupInformation.java:1121)
at org.apache.hadoop.mapred.Child.main(Child.java:249)
Caused by: java.lang.ClassNotFoundException: com.wesley.hadoop.WordCount$TokenizerMapper
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:820)
at org.apache.hadoop.conf.Configuration.getClass(Configuration.java:865)
... 8 more

13/05/16 15:00:08 WARN mapred.JobClient: Error reading task outputhadoop-master
13/05/16 15:00:08 WARN mapred.JobClient: Error reading task outputhadoop-master


求指点,网上查了很多资料,一一验证还是不行啊~
寄生虫 2013-05-17
使用hadoop-eclipse-plugin运行map/reducer代码,会在workspace/.metadata/.plugins/org.apache.hadoop.eclipse生成jar包文件,编辑jar包中的MANIFEST.MF文件,将main class的“.”替换成“/”,以避免报找不到关联类的错误
hanwesley 2013-05-20
寄生虫 写道
使用hadoop-eclipse-plugin运行map/reducer代码,会在workspace/.metadata/.plugins/org.apache.hadoop.eclipse生成jar包文件,编辑jar包中的MANIFEST.MF文件,将main class的“.”替换成“/”,以避免报找不到关联类的错误

Manifest-Version: 1.0
Ant-Version: Apache Ant 1.8.4
Created-By: 1.6.0_22-b04 (Sun Microsystems Inc.)
Bundle-ManifestVersion: 2
Bundle-Name: MapReduce Tools for Eclipse
Bundle-SymbolicName: org.apache.hadoop.eclipse;singleton:=true
Bundle-Version: 0.18
Bundle-Activator: org.apache.hadoop.eclipse.Activator
Bundle-Localization: plugin
Require-Bundle: org.eclipse.ui,org.eclipse.core.runtime,org.eclipse.jd
t.launching,org.eclipse.debug.core,org.eclipse.jdt,org.eclipse.jdt.co
re,org.eclipse.core.resources,org.eclipse.ui.ide,org.eclipse.jdt.ui,o
rg.eclipse.debug.ui,org.eclipse.jdt.debug.ui,org.eclipse.core.express
ions,org.eclipse.ui.cheatsheets,org.eclipse.ui.console,org.eclipse.ui
.navigator,org.eclipse.core.filesystem,org.apache.commons.logging
Eclipse-LazyStart: true
Bundle-ClassPath: classes/,lib/hadoop-core.jar,lib/commons-cli-1.2.jar
,lib/commons-httpclient-3.0.1.jar,lib/jackson-core-asl-1.8.8.jar,lib/
jackson-mapper-asl-1.8.8.jar,lib/commons-configuration-1.6.jar,lib/co
mmons-lang-2.4.jar,lib/hadoop-core.jar
Bundle-Vendor: Apache Hadoop


这是MANIFEST。MF内容,没有MainClass呀
sgq0085 2013-05-21
环境eclipse,运行同样的代码,没有问题,你应该查一下是不是环境的问题
bewithme 2013-05-23
包版本不对
hanwesley 2013-05-24
bewithme 写道
包版本不对

1.0.4 应该没问题吧
hanyingme 2014-08-05
您好,请问这个问题 是怎么解决的呢?我也遇到了同样的问题,一直解决不了。
Global site tag (gtag.js) - Google Analytics