1

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.

jocassid
  • 4,429
  • 1
  • 13
  • 6
CGG
  • 253
  • 1
  • 11
  • 22
  • 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 Oct 12 '18 at 04:17
  • 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 Oct 13 '18 at 15:40
  • Not sure about that... I typically suggest that you use Maven or Gradle to ensure all versions are correct – OneCricketeer Oct 14 '18 at 14:53
  • I downloaded Hadoop and I am compiling one 'file.java' in the server. – CGG Oct 14 '18 at 15:07
  • I understand that, but Hadoop alone requires at least maybe 20 other JAR files to be on your classpath to compile that single java file. And FWIW, not very many people actually use plain MapReduce anymore – OneCricketeer Oct 14 '18 at 16:29
  • 1
    Ok, but this is a basic example in which you only require a few to test Hadoop. This is why this is interesting. – CGG Oct 14 '18 at 17:18

1 Answers1

1

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
Ricolove
  • 11
  • 1