[HADOOP] Hadoop Java 오류 : "main"스레드의 예외 java.lang.NoClassDefFoundError : WordCount (잘못된 이름 : org / myorg / WordCount)
HADOOPHadoop Java 오류 : "main"스레드의 예외 java.lang.NoClassDefFoundError : WordCount (잘못된 이름 : org / myorg / WordCount)
나는 새삼 스럽다. 나는 단일 노드에서 hadoop을 설정하기 위해 maichel-noll 튜토리얼을 따라 갔다. 나는 WordCount 프로그램을 실행 해 보았다. 이것은 내가 사용한 코드이다.
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;
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();
Job job = Job.getInstance(conf, "WordCount");
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(args[0]));
FileOutputFormat.setOutputPath(job, new Path(args[1]));
System.exit(job.waitForCompletion(true) ? 0 : 1);
}
}
이것은 내가 그것을 실행하려고 할 때 얻는 것이다.
hduser@aswin-HP-Pavilion-15-Notebook-PC:/usr/local/hadoop$ bin/hadoop jar wc.jar WordCount /home/hduser/gutenberg /home/hduser/gutenberg-output/sample.txt
Exception in thread "main" java.lang.NoClassDefFoundError: WordCount (wrong name: org/myorg/WordCount)
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(ClassLoader.java:788)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
at java.net.URLClassLoader.defineClass(URLClassLoader.java:447)
at java.net.URLClassLoader.access$100(URLClassLoader.java:71)
at java.net.URLClassLoader$1.run(URLClassLoader.java:361)
at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
at java.lang.ClassLoader.loadClass(ClassLoader.java:411)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:270)
at org.apache.hadoop.util.RunJar.main(RunJar.java:205)
아무도 도와주세요. 내 수업 경로 :
hduser@aswin-HP-Pavilion-15-Notebook-PC:/usr/local/hadoop$ hadoop classpath
/usr/local/hadoop/etc/hadoop:/usr/local/hadoop/share/hadoop/common/lib/*:/usr/local/hadoop/share/hadoop/common/*:/usr/local/hadoop/share/hadoop/hdfs:/usr/local/hadoop/share/hadoop/hdfs/lib/*:/usr/local/hadoop/share/hadoop/hdfs/*:/usr/local/hadoop/share/hadoop/yarn/lib/*:/usr/local/hadoop/share/hadoop/yarn/*:/usr/local/hadoop/share/hadoop/mapreduce/lib/*:/usr/local/hadoop/share/hadoop/mapreduce/*:/usr/lib/jvm/java-7-openjdk-i386/lib/tools.jar:/usr/local/hadoop/contrib/capacity-scheduler/*.jar
해결법
-
==============================
1.이 시도,
이 시도,
import java.io.IOException; import java.util.Iterator; import java.util.StringTokenizer; import org.apache.hadoop.fs.Path; import org.apache.hadoop.io.IntWritable; import org.apache.hadoop.io.LongWritable; import org.apache.hadoop.io.Text; import org.apache.hadoop.mapred.FileInputFormat; import org.apache.hadoop.mapred.FileOutputFormat; import org.apache.hadoop.mapred.JobClient; import org.apache.hadoop.mapred.JobConf; import org.apache.hadoop.mapred.MapReduceBase; import org.apache.hadoop.mapred.Mapper; import org.apache.hadoop.mapred.OutputCollector; import org.apache.hadoop.mapred.Reducer; import org.apache.hadoop.mapred.Reporter; import org.apache.hadoop.mapred.TextInputFormat; import org.apache.hadoop.mapred.TextOutputFormat; public class WordCount { public static class Map extends MapReduceBase implements Mapper<LongWritable, Text, Text, IntWritable> { @Override 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()) { value.set(tokenizer.nextToken()); output.collect(value, new IntWritable(1)); } } } public static class Reduce extends MapReduceBase implements Reducer<Text, IntWritable, Text, IntWritable> { @Override 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.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); } }
다음 명령을 실행
bin/hadoop jar WordCount.jar WordCount /hdfs_Input_filename /output_filename
귀하의 코드가 특정 패키지에 있다면 클래스 이름과 함께 패키지 이름을 언급해야합니다.
bin/hadoop jar WordCount.jar PakageName.WordCount /hdfs_Input_filename /output_filename
-
==============================
2.이것은 미친 듯이 들릴지도 모릅니다. org.myorg 패키지를 추가했습니다. 내 코드로 다시 컴파일했다. 클래스 파일을 org / myorg 폴더에 넣고이를 사용하여 jar 파일을 만들었습니다. 그런 다음 jar wc.jar org.myorg.WordCount 명령을 사용하여 실행했으며 성공적으로 실행되었습니다. 누군가가 실제로 어떻게 달렸는지 설명 할 수 있다면 좋을 것입니다. D. 어쨌든, 나를 도와 줘서 고마워.
이것은 미친 듯이 들릴지도 모릅니다. org.myorg 패키지를 추가했습니다. 내 코드로 다시 컴파일했다. 클래스 파일을 org / myorg 폴더에 넣고이를 사용하여 jar 파일을 만들었습니다. 그런 다음 jar wc.jar org.myorg.WordCount 명령을 사용하여 실행했으며 성공적으로 실행되었습니다. 누군가가 실제로 어떻게 달렸는지 설명 할 수 있다면 좋을 것입니다. D. 어쨌든, 나를 도와 줘서 고마워.
-
==============================
3.수업 중에 패키지를 사용하고 있습니다. 그래서 당신 명령은 있어야합니다.
수업 중에 패키지를 사용하고 있습니다. 그래서 당신 명령은 있어야합니다.
bin/hadoop jar wc.jar org.myorg.WordCount /home/hduser/gutenberg /home/hduser/gutenberg-output/sample.txt
-
==============================
4.나는 네가 여기 실수 한 것 같아.
나는 네가 여기 실수 한 것 같아.
/usr/local/hadoop$ bin/hadoop jar wc.jar WordCount /home/hduser/gutenberg /home/hduser/gutenberg-output/sample.txt
다음과 같이 변경하십시오.
/usr/local/hadoop$ bin/hadoop jar wc.jar org.myorg.WordCount /home/hduser/gutenberg /home/hduser/gutenberg-output/sample.txt
그게 효과가있다.
@Aswin Alagappan : 이유는 무엇입니까? jar 파일은 경로를 지정합니다. jar 파일이 "jar \ org \ myorg"경로에 있기 때문에 JVM에서 클래스를 찾을 수 없습니다. 알다?
-
==============================
5.jar 파일에 중첩 클래스 (예 : TokenizerMapper 및 IntSumReducer)를 명시 적으로 포함 시키십시오. 여기 내가 어떻게 그랬는가 :
jar 파일에 중첩 클래스 (예 : TokenizerMapper 및 IntSumReducer)를 명시 적으로 포함 시키십시오. 여기 내가 어떻게 그랬는가 :
jar cvf WordCount.jar WordCount.class WordCount\$TokenizerMapper.class WordCount\$IntSumReducer.class
from https://stackoverflow.com/questions/26700910/hadoop-java-error-exception-in-thread-main-java-lang-noclassdeffounderror-w by cc-by-sa and MIT license
'HADOOP' 카테고리의 다른 글
[HADOOP] Java JDBC를 통해 하이브 연결 (0) | 2019.07.21 |
---|---|
[HADOOP] Spark에서 RDD 비싼 작업의 기록을 세고 있습니까? (0) | 2019.07.21 |
[HADOOP] 스파크 스트리밍 : 마이크로 배치 병렬 실행 (0) | 2019.07.21 |
[HADOOP] '파일을 해결하는 방법은 hadoop에서 1 대신'0 노드에만 복제 할 수 있습니까? ' (0) | 2019.07.21 |
[HADOOP] 호스트 시스템에서 클라이언트로 VM에서 실행중인 HBase에 액세스 (0) | 2019.07.21 |