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はルートにありますが、特権の問題はありますか?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。ディレクトリには、hadoopページ( http://ftp.ps.pl/pub/apache/hadoop/common/stable/hadoop-1.0.4-bin.tar.gzC:\Users\user\Desktop\hadd2\* )からダウンロードした*.jarsがあります。成功してコンパイルされたアプリ。

于 2013-03-14T06:20:48.467 に答える
0

ここのコンパイラは、MapReduceクラスについて不平を言っています。Hadoopライブラリにない場合は、クラスパスまたはインポートステートメントを確認してください。

于 2013-03-14T08:38:50.133 に答える
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 に答える
-1

[解決済み]

私はを使用していnew hadoop apiて、pgmはold api

于 2013-11-16T05:29:45.830 に答える