Apache Kafka appends wrong JAVA path

I have installed the OpenJDK Headless JAVA package on a Ubuntu 16.04 which works fine. My JAVA_HOME variable is set to:

/usr/lib/jvm/java-8-openjdk-amd64/jre/bin/java

But when I'm starting Apache Kafka it tries to load JAVA from the wrong path. It looks like it is appending /bin/java to the end of the JAVA_HOME variable.

$ sudo /opt/kafka/kafka_2.11-1.1.0/bin/kafka-server-start.sh /opt/kafka/kafka_2.11-1.1.0/config/server.properties
/opt/kafka/kafka_2.11-1.1.0/bin/kafka-run-class.sh: line 271: /usr/lib/jvm/java-8-openjdk-amd64/jre/bin/java/bin/java: Not a directory
/opt/kafka/kafka_2.11-1.1.0/bin/kafka-run-class.sh: line 271: exec: /usr/lib/jvm/java-8-openjdk-amd64/jre/bin/java/bin/java: cannot execute: Not a directory

I tried changing JAVA_HOME to just:

/usr/lib/jvm/java-8-openjdk-amd64/jre/

But it is still pointing to the same (invalid) java executable.

I then inspected the 271 line in kafka-run-class.sh which says:

exec $JAVA $KAFKA_HEAP_OPTS $KAFKA_JVM_PERFORMANCE_OPTS $KAFKA_GC_LOG_OPTS $KAFKA_JMX_OPTS $KAFKA_LOG4J_OPTS -cp $CLASSPATH $KAFKA_OPTS "$@"

So it looks like it is using the JAVA variable, so I try to export JAVA="/usr/lib/jvm/java-8-openjdk-amd64/jre/bin/java" without any luck.

Can anyone explain why this is happening, and how I can solve this?

2

1 Answer

  1. sudo vi ~/.bashrc
  2. Edit your java home to below
 export JAVA_HOME=/usr/lib/jvm/java-8-openjdk-amd64/jre/ export PATH=$PATH:$JAVA_HOME/bin
  1. source ~/.bashrc
  2. then start Kafka
 ~/kafka/bin/kafka-server-start.sh ~/kafka/config/server.properties

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

You Might Also Like