1
votes

I have installed Hadoop 3.1.1 and it is working. However, when I try to compile the WordCount example, I am receiving this error:

/usr/local/hadoop/libexec/hadoop-functions.sh: line 2358: HADOOP_COM.SUN.TOOLS.JAVAC.MAIN_USER: bad substitution
/usr/local/hadoop/libexec/hadoop-functions.sh: line 2453: HADOOP_COM.SUN.TOOLS.JAVAC.MAIN_OPTS: bad substitution

To compile, I used the next line:

hadoop com.sun.tools.javac.Main WordCount.java

I have the next variables in the .bashrc:

#Hadoop variables
export HADOOP_HOME=/usr/local/hadoop
export CONF=$HADOOP_HOME/etc/hadoop
export PATH=$PATH:$HADOOP_HOME/bin
export PATH=$PATH:$HADOOP_HOME/sbin

#Java home
export JAVA_HOME=${JAVA_HOME}/java-8-oracle

#Path Java Tools
export HADOOP_CLASSPATH=$JAVA_HOME/lib/tools.jar

This time I am using Java 8 of Oracle because the apt-get of Ubuntu 18.08 LTS does not give me the option of installing the OpenJDK8. I have updated and upgraded Ubuntu.

I have read a lot of different post and possible solutions, but I cannot solve it.

1
You don't need to Hadoop command to compile code you can just use javac -cp .:$HADOOP_CLASSPATH WordCount.java, but if you want to do it your way, com-sun isn't a valid package prefix - OneCricketeer
com-sun was a mistake when I write the problem. If I try your way, I receive a lot of errors which are about that the different Hadoop package do not exist. - CGG
Not sure about that... I typically suggest that you use Maven or Gradle to ensure all versions are correct - OneCricketeer
I downloaded Hadoop and I am compiling one 'file.java' in the server. - CGG
Ok, but this is a basic example in which you only require a few to test Hadoop. This is why this is interesting. - CGG

1 Answers

1
votes

This is a viable solution I found in https://janzhou.org/2014/how-to-compile-hadoop.html

Set the HADOOP_CLASSPATH:

export HADOOP_CLASSPATH=$(bin/hadoop classpath)

Compile:

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