How can you compile WordCount.java on Cloudera 4?

I am trying to compile a simple example of converting WordCount.java to installing Cloudera on linux (CentOS) 4. I continue to encounter compiler errors when I refer to any of the hadoop classes, but I can’t understand which cans are hundreds under / usr / lib / I hadoop I need to add to my classpath to compile things. Any help would be greatly appreciated! I would like most to be a java file for word counting (in case the one I found is bad for some reason) along with the corresponding command to compile and run it.

I am trying to do this using only javac and not Eclipse. My main problem anyway is what exactly are the Hadoop libraries from installing Cloudera 4, which I need to enable in order to get a classic WordCount example for compilation. Basically, I need to put the Java MapReduce API classes (Mapper, Reducer, etc.) in my classpath.

+4
source share
4 answers

I have a script that builds my adoop classes. Try:

#!/bin/bash program=`echo $1 | awk -F "." '{print $1}'` if [ ! -d "${program}_classes" ] then mkdir ${program}_classes/; fi javac -classpath /usr/lib/hadoop/hadoop-common-2.0.0-cdh4.0.1.jar:/usr/lib/hadoop/client/h\ adoop-mapreduce-client-core-2.0.0-cdh4.0.1.jar -d ${program}_classes/ $1 jar -cvf ${program}.jar -C ${program}_classes/ .; 

You probably lacked key jars:

  /usr/lib/hadoop/hadoop-common-2.0.0-cdh4.0.1.jar 

and

 /usr/lib/hadoop/client/hadoop-mapreduce-client-core-2.0.0-cdh4.0.1.jar 
+5
source

If you are using the Cloudera CDH4 virtual machine, you need to run the following:

 javac -classpath /usr/lib/hadoop/hadoop-common-2.0.0-cdh4.0.0.jar:/usr/lib/hadoop/client/hadoop-mapreduce-client-core-2.0.0-cdh4.0.0.jar -d wordcount_classes WordCount.java 
+2
source

Or you can export the environment:

 export JAVA_HOME=/usr/java/default export PATH=${JAVA_HOME}/bin:${PATH} export HADOOP_CLASSPATH=${JAVA_HOME}/lib/tools.jar 

and use the following commands:

 $ bin/hadoop com.sun.tools.javac.Main WordCount.java $ jar cf wc.jar WordCount*.class 
+1
source

If you are using Eclipse, add the Hadoop packages. you can get it from java2s or any similar sites. I could not say, I do not know anything about what you have done so far.

0
source

All Articles