0

I am trying to compile the simple WordCount.java program using Hadoop MapReduce using the command: hadoop com.sun.tools.javac.Main WordCount.java

But I keep getting the message:

Error: Could not find or load main class com.sun.tools.javac.Main

My exports are as follows:

export JAVA_HOME=/Library/Java/JavaVirtualMachine/jdk1.8.0_101.jdk/Contents/Home
export HADOOP_HOME=/usr/local/Cellar/hadoop/2.7.1
export HADOOP_PREFIX=$HADOOP_HOME/libexec
export HADOOP_MAPRED_HOME=$HADOOP_PREFIX
export HADOOP_COMMON_HOME=$HADOOP_PREFIX
export HADOOP_HDFS_HOME=$HADOOP_PREFIX
export YARN_HOME=$HADOOP_PREFIX
export HADOOP_COMMON_LIB_NATIVE_DIR=$HADOOP_PREFIX
export HADOOP_CLASSPATH=$JAVA_HOME/lib/tools.jar
export PATH=$PATH:$HADOOP_HOME/sbin:$HADOOP_HOME/bin

I've checked my JAVA_HOME/lib directory and confirmed that the tools.jar file is there.

My other haddop functions seem to be working properly. I can run hadoop version and it returns my hadoop version number. I can run hdfs dfs -ls and it returns the listing of my hdfs directory.

Any help in figuring out why I can't compile would be greatly appreciated

Philipp Maurer
  • 2,480
  • 6
  • 18
  • 25
ThatOneGuy
  • 160
  • 4
  • 12
  • Is your path to java is proper? check it using java version command "java -version" – Mahek Dec 09 '16 at 09:28
  • 1
    Possible duplicate of [Java: com.sun.tools.javac.Main not found when trying to compile Hadoop program](https://stackoverflow.com/questions/27299273/java-com-sun-tools-javac-main-not-found-when-trying-to-compile-hadoop-program) – Philipp Maurer Apr 20 '18 at 11:44

1 Answers1

2

Your error might be, that the JAVA_HOME environment variable is not set correctly.

To solve the issue I used this answer to set the variable correctly.

Set HADOOP_CLASSPATH environment variable
export HADOOP_CLASSPATH=$JAVA_HOME/lib/tools.jar

After that, the error was gone.

Philipp Maurer
  • 2,480
  • 6
  • 18
  • 25
Shusen Yi
  • 779
  • 7
  • 6