About manually compiling the Hadoop Getting started example WordCount and performing
The previous example is to run the example with a jar package already compiled in Hadoop.
But this time, to manually compile an instance, practice
I didn't expect to have a little trouble.
[[email protected] wordcount]# Hadoop jar Wordcount.jar /wc/input/wc/outputexception in thread "main" Java.lang.ClassNotFoundException:/wc/input at JAVA.LANG.CLASS.FORNAME0 (Native Method) at Java.lang.Class.forName (class.java:348) at Org.apache.hadoop.util.RunJar.main (runjar.java:153)
And always report this mistake.
1. Ready to compile files and environment
First, find a place to copy the Wordcount.java from the Hadoop installation directory.
In the folder where the Wordcount.java is located, build a folder, built here is wordcount, used for compiling
[Email protected] wordcount_class]# Lscommons-cli-1.2.jar hadoop-core-1.2.1.jar wordcount.java[[email Protected] wordcount_class]# mkdir wordcount[[email protected] wordcount_class]# Lscommons-cli-1.2.jar Hadoop-core-1.2.1.jar WordCount
2. Compile to Folder
The following is a compilation of
Two jar package required: Hadoop-core-1.2.1.jar,commons-cli-1.2.jar
These two jar packages are available in the Hadoop installation directory
Hadoop-core-1.2.1.jar is under the root directory,
Commons-cli-1.2.jar is under the Lib directory under the root directory
You can use an absolute path, or you can copy the two jar packages to the WordCount folder you created earlier.
The compilation process is:
Javac-classpath Hadoop-core-1.2.1.jar:commons-cli-1.2.jar wordcount.java-d WordCount
[Email protected] wordcount_class]# Javac-classpath Hadoop-core-1.2.1.jar:commons-cli-1.2.jar wordcount.java-d Wordcount[[email protected] wordcount_class]# CD Wordcount[[email protected] wordcount]# lsorg
As explained here,-classpath can be abbreviated as-CP, followed by the path of the jar package to be used.
Wordcount.java is the Java source file we're going to use.
-D is compiled into the following Wordcoun folder
The namespaces in the Wordcount.java are as follows, if not changed,
Package org.apache.hadoop.examples;
There will be a lot of nested subfolders generated under the WordCount folder.
such as WordCount under the org,org under the Apache, and so on, until examples is the last directory
3. Packaging Jar Package
After compiling, we're going to package it as a jar.
At this point, go to the WordCount directory and execute the command:
Jar CVF Wordcount.jar *
At this time, a Wordcount.jar bag will appear under the WordCount.
4. Execute the JAR package under Hadoop
And then it's going to be executed, and there's something going on in the HDFs file system that's not written here.
The special note here is the namespace in WordCount, which is what is in the package and the main class is placed behind the jar.
This is org.apache.hadoop.example.WordCount.
[Email protected] wordcount]# Hadoop dfs-rmr/wc/outputdeleted hdfs://centos:9000/wc/output[[email protected] wordcount]# Hadoop jar Wordcount.jar org.apache.hadoop.examples.wordcount/wc/input/wc/output
At Org.apache.hadoop.util.RunJar.main (runjar.java:153)