Support Questions
Find answers, ask questions, and share your expertise
Announcements
Check out our newest addition to the community, the Cloudera Innovation Accelerator group hub.

compilation of hadoop word count example

Master Collaborator

I am following apache instructions at

https://hadoop.apache.org/docs/r2.5.2/hadoop-mapreduce-client/hadoop-mapreduce-client-core/MapReduce...

when I try to compile the java code I get the error :

[root@hadoop1 sami]# hadoop  WordCount.java
Error: Could not find or load main class WordCount.java
[root@hadoop1 sami]# hadoop com.sun.tools.javac.Main WordCount.java
Error: Could not find or load main class com.sun.tools.javac.Main
[root@hadoop1 sami]#
6 REPLIES 6

@Sami Ahmad

Do you have the JDK installed? Is the JAVA_HOME environment variable set for the root user (since your example is using root)?

Notice the instructions have

Assuming environment variables are set as follows:

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

Master Collaborator

yes I have jdk installed but I cant find the javac utility in the installed folders. all the above variables are set properly.

It sounds like you have the JRE installed and not the JDK.

@Sami Ahmad

I assume that you try to follow: https://hadoop.apache.org/docs/stable/hadoop-mapreduce-client/hadoop-mapreduce-client-core/MapReduce...

Execute the following to determine whether JAVA_HOME and HADOOP_CLASSPATH are properly set:

echo $JAVA_HOME

echo $HADOOP_CLASSPATH

If they are properly set, you could use the following to compile, create jar and run.

To compile:

javac -classpath ${HADOOP_CLASSPATH} -d WordCount/ WordCount.java

To create jar:

jar -cvf WordCount.jar -C WordCount/ .

To run:

hadoop jar WordCount.jar org.myorg.WordCount test/ testout

Master Collaborator

I have jdk installed but it does not contain "javac" ?

[root@hadoop1 ~]# which javac /usr/bin/which: no javac in (/usr/lib64/qt-3.3/bin:/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/usr/hdp/current/kafka-broker/bin:/usr/local/maven/bin:/usr/lib/jvm/jre-1.7.0-openjdk.x86_64/bin:/root/bin) [root@hadoop1 ~]# echo $JAVA_HOME /usr/lib/jvm/jre-1.7.0-openjdk.x86_64 [root@hadoop1 ~]# cd $JAVA_HOME/bin [root@hadoop1 bin]# ls java keytool orbd pack200 policytool rmid rmiregistry servertool tnameserv unpack200 [root@hadoop1 bin]# cd .. [root@hadoop1 jre-1.7.0-openjdk.x86_64]# ls bin lib [root@hadoop1 jre-1.7.0-openjdk.x86_64]# cd .. [root@hadoop1 jvm]# ls java-1.5.0-gcj-1.5.0.0 jre jre-1.6.0 jre-1.7.0-openjdk.x86_64 java-1.6.0-openjdk-1.6.0.38.x86_64 jre-1.5.0 jre-1.6.0-openjdk.x86_64 jre-gcj java-1.7.0-openjdk-1.7.0.99.x86_64 jre-1.5.0-gcj jre-1.7.0 jre-openjdk [root@hadoop1 jvm]# cd java-1.7.0-openjdk-1.7.0.99.x86_64 [root@hadoop1 java-1.7.0-openjdk-1.7.0.99.x86_64]# ls ASSEMBLY_EXCEPTION jre LICENSE THIRD_PARTY_README [root@hadoop1 java-1.7.0-openjdk-1.7.0.99.x86_64]# ls jre bin lib [root@hadoop1 java-1.7.0-openjdk-1.7.0.99.x86_64]# ls jre/bin java keytool orbd pack200 policytool rmid rmiregistry servertool tnameserv unpack200 [root@hadoop1 java-1.7.0-openjdk-1.7.0.99.x86_64]#

It looks like you have the JRE installed, not the JDK. The JRE allows you to run java applications, but does not let you compile.