2

我试过这段代码:

javac -verbose -classpath /var/root/hadoop-1.0.4/hadoop-1.0.4-core.jar WordCount.java -d /Users/amrita/desktop/hadoop/javatrail/wordcount_classes

我只是收到以下错误:

parsing started WordCount.java]
[parsing completed 12ms]
[search path for source files: /var/root/hadoop-1.0.4/hadoop-1.0.4-core.jar]
[search path for class files: /System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Classes/jsfd.jar,/System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Classes/classes.jar,/System/Library/Frameworks/JavaVM.framework/Frameworks/JavaRuntimeSupport.framework/Resources/Java/JavaRuntimeSupport.jar,/System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Classes/ui.jar,/System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Classes/laf.jar,/System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Classes/sunrsasign.jar,/System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Classes/jsse.jar,/System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Classes/jce.jar,/System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Classes/charsets.jar,/Library/Java/Extensions/RXTXcomm.jar,/System/Library/Java/Extensions/AppleScriptEngine.jar,/System/Library/Java/Extensions/dns_sd.jar,/System/Library/Java/Extensions/j3daudio.jar,/System/Library/Java/Extensions/j3dcore.jar,/System/Library/Java/Extensions/j3dutils.jar,/System/Library/Java/Extensions/jai_codec.jar,/System/Library/Java/Extensions/jai_core.jar,/System/Library/Java/Extensions/mlibwrapper_jai.jar,/System/Library/Java/Extensions/MRJToolkit.jar,/System/Library/Java/Extensions/QTJava.zip,/System/Library/Java/Extensions/vecmath.jar,/System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Home/lib/ext/apple_provider.jar,/System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Home/lib/ext/dnsns.jar,/System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Home/lib/ext/localedata.jar,/System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Home/lib/ext/sunjce_provider.jar,/System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Home/lib/ext/sunpkcs11.jar,/var/root/hadoop-1.0.4/hadoop-1.0.4-core.jar]
[loading java/io/IOException.class(java/io:IOException.class)]
WordCount.java:5: package org.apache.hadoop.fs does not exist
import org.apache.hadoop.fs.Path;
                           ^
WordCount.java:6: package org.apache.hadoop.conf does not exist
import org.apache.hadoop.conf.*;
^
WordCount.java:7: package org.apache.hadoop.io does not exist
import org.apache.hadoop.io.*;
^
WordCount.java:8: package org.apache.hadoop.mapred does not exist
import org.apache.hadoop.mapred.*;
^
WordCount.java:9: package org.apache.hadoop.util does not exist
import org.apache.hadoop.util.*;
^
[loading java/lang/Object.class(java/lang:Object.class)]
[loading java/lang/String.class(java/lang:String.class)]
[loading java/lang/Exception.class(java/lang:Exception.class)]
WordCount.java:11: cannot find symbol
symbol  : class MapReduceBase
location: class org.myorg.WordCount
    public static class Map extends MapReduceBase implements Mapper<LongWritable, Text, Text, IntWritable> {
                                    ^
WordCount.java:11: cannot find symbol
symbol  : class Mapper
location: class org.myorg.WordCount
    public static class Map extends MapReduceBase implements Mapper<LongWritable, Text, Text, IntWritable> {
                                                             ^
WordCount.java:11: cannot find symbol
symbol  : class LongWritable
location: class org.myorg.WordCount
    public static class Map extends MapReduceBase implements Mapper<LongWritable, Text, Text, IntWritable> {
                                                                    ^
   [total 406ms]
48 errors

我的类路径有什么问题吗?如果是这样,我怎样才能获得正确的类路径?我的 WordCount.java 在 /Users/amrita/.... 和 hadoop 在 root 中,是否有任何权限问题?我无法生成 WordCount.class

源代码:WordCount.java

package org.myorg;
import java.io.IOException;
import java.util.*;

import org.apache.hadoop.fs.Path;
import org.apache.hadoop.conf.*;
import org.apache.hadoop.io.*;
import org.apache.hadoop.mapred.*;
import org.apache.hadoop.util.*;
public class WordCount {
    public static class Map extends MapReduceBase implements Mapper<LongWritable, Text, Text, IntWritable> {
        private final static IntWritable one = new IntWritable(1);
        private Text word = new Text();
        public void map(LongWritable key, Text value, OutputCollector<Text, IntWritable> output, Reporter reporter) throws IOException {
            String line = value.toString();
            StringTokenizer tokenizer = new StringTokenizer(line);
            while (tokenizer.hasMoreTokens()) {
                word.set(tokenizer.nextToken());
                output.collect(word, one);
            }
        }
    }
    public static class Reduce extends MapReduceBase implements Reducer<Text, IntWritable, Text, IntWritable> {
         public void reduce(Text key, Iterator<IntWritable> values, OutputCollector<Text, IntWritable> output, Reporter reporter) throws IOException {
             int sum = 0;
             while (values.hasNext()) {
                 sum += values.next().get();
             }
             output.collect(key, new IntWritable(sum));
         }
    }
    public static void main(String[] args) throws Exception {
        JobConf conf = new JobConf(WordCount.class);
        conf.setJobName("wordcount");
        conf.setOutputKeyClass(Text.class);
        conf.setOutputValueClass(IntWritable.class);
        conf.setMapperClass(Map.class);
        conf.setCombinerClass(Reduce.class);
        conf.setReducerClass(Reduce.class);
         conf.setInputFormat(TextInputFormat.class);
         conf.setOutputFormat(TextOutputFormat.class);
         FileInputFormat.setInputPaths(conf, new Path(args[0]));
         FileOutputFormat.setOutputPath(conf, new Path(args[1]));
         JobClient.runJob(conf);
    }
}
4

4 回答 4

1

我创建了导入 hadoop 类的简单程序:

import org.apache.hadoop.fs.Path;
import org.apache.hadoop.conf.*;
import org.apache.hadoop.io.*;
import org.apache.hadoop.mapred.*;
import org.apache.hadoop.util.*;
public class WordCount {
    public static void main(String args[]) {
        System.out.println("test");
    }
}

并使用此命令对其进行编译javac -classpath "C:\Users\user\Desktop\hadd2\*" WordCount.java。在目录C:\Users\user\Desktop\hadd2\*中,我从 hadoop 页面(http://ftp.ps.pl/pub/apache/hadoop/common/stable/hadoop-1.0.4-bin.tar.gz)下载了 *.jars。应用程序编译成功。

于 2013-03-14T06:20:48.467 回答
0

hduser@Linux:~/hadoop$ javac -classpath /home/hduser/hadoop/hadoop-core-1.1.2.jar -d wordcount_classes WordCount.java

hduser@Linux:~/hadoop$

于 2013-09-10T12:47:40.937 回答
0

这里的编译器抱怨 MapReduce 类。如果您的 hadoop 库中没有,请检查其类路径或导入语句。

于 2013-03-14T08:38:50.133 回答
-1

[解决了]

我使用的new hadoop api是 pgm 和old api

于 2013-11-16T05:29:45.830 回答