27

I installed Kafka on a remote server, and when I tried to run

~/kafka/bin/zookeeper-server-start.sh ~/kafka/config/zookeeper.properties

And I received an error

Unrecognized VM option 'PrintGCDateStamps'

And the kafka server failed to start. This was not being run in a vm, and was being run directly on Ubuntu Server 16.04 with Java properly installed. Any way this can be corrected simply?

1

8 Answers 8

32

Actually, Kafka works fine with newer versions of Java. I had the same problem, and found an error in the kafka/bin/kafka-run-class.sh script, where the Java version was incorrectly parsed.

This line grabs too much of the version string:

JAVA_MAJOR_VERSION=$($JAVA -version 2>&1 | sed -E -n 's/.* version "([^.-]*).*"/\1/p')

This makes the if [[ "$JAVA_MAJOR_VERSION" -ge "9" ]] condition fail to identify the correct Java version, and adds some unsupported GC options.

Changing the line above to this solved my problem:

JAVA_MAJOR_VERSION=$($JAVA -version 2>&1 | sed -E -n 's/.* version "([^.-]*).*/\1/p')

I have reported this as an issue with Kafka. The issue can be found here: https://issues.apache.org/jira/browse/KAFKA-6855

EDIT: There is a committed fix for this: https://github.com/apache/kafka/commit/e9f86c3085fa8b65e77072389e0dd147b744f117

7
  • I updated the above line. Still does not work for me. I have Ubuntu 16.04 with Java version: java 10.0.1 2018-04-17 Java(TM) SE Runtime Environment 18.3 (build 10.0.1+10) Java HotSpot(TM) 64-Bit Server VM 18.3 (build 10.0.1+10, mixed mode). ERROR IS ::: Classpath is empty. Please build the project first e.g. by running './gradlew jar -PscalaVersion=2.11.12' Jun 11, 2018 at 2:52
  • That is not the same error as in the original question, @NeerajKumar You probably have some other error too, with your classpath. Jun 12, 2018 at 12:41
  • NeerajKumar: See if you have any spaces in your directory path. Try moving to another path without any space. (hoping you downloaded the binary). And BTW, this issue is different than what is being asked in the original question.
    – Hafeez
    Jun 13, 2018 at 7:31
  • 1
    Thank you Anders, this solved my problem of the Java version issue. Now Zookeeper runs fine. Upped the answer.
    – Hafeez
    Jun 13, 2018 at 7:33
  • 2
    Thank you for this. Works great :)
    – datoml
    Jun 22, 2018 at 8:05
10

Same issue on Ubuntu 16.04 with oracle jdk 9 installed, I have also tried openjdk 1.9 and got the same error. But when I try other version jdk, I found that oracle jdk 8 and openjdk 1.8 are both ok.

So just check out what version of java you're using, maybe you can install or switch to other version of jdk by:

update-alternatives --display java
update-alternatives --config java
java -version
2
  • 2
    Deleted my answer in favor of this one. Thanks! Oct 25, 2017 at 16:07
  • 1
    Kafka actually works fine with newer versions of Java. The issue is due to a bug in the version detection script, and that issue is currently being solved. See my answer. May 11, 2018 at 8:06
5

Like the other answers -- I got this to work on Java 9. Had to make the following changes:

  1. Edit the file bin/kafka-run-class.sh

  2. Near the end of the file (around line 248) find the following block:

if [ "x$GC_LOG_ENABLED" = "xtrue" ]; then GC_LOG_FILE_NAME=$DAEMON_NAME$GC_FILE_SUFFIX KAFKA_GC_LOG_OPTS="-Xloggc:$LOG_DIR/$GC_LOG_FILE_NAME -verbose:gc -XX:+PrintGCDetails -XX:+PrintGCDateStamps -XX:+PrintGCTimeStamps " fi

  1. Remove the 2 flags : -XX:+PrintGCDateStamps -XX:+PrintGCTimeStamps and save the file.

  2. Kafka should start okay on Java 9

2
  • this worked for me when I did a nano bin/kafka-run-class.sh Ctrl W to find to go to the line
    – veritas
    Oct 18, 2020 at 12:56
  • I didn't had a problem iwth kafka, but i had with seata, and your 3rd point worked on my case only.
    – rpajaziti
    Sep 29, 2022 at 10:22
2

So I found an answer and wanted to post it in case anyone else had this problem. In the kafka/bin/kafka-run-class.sh at the very bottom there is a part where it says

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

Delete the $KAFKA_GC_LOG_OPTS option. Might be a hack, but at least it gets the kafka zookeeper server to start!

1
  • 3
    You should probably not remove the $KAFKA_GC_LOG_OPTS variable instead, find out where it's being set and then change the value there. The PrintGCDateStamps might be from a newer version of Java than you have installed, but you'd probably want to enable some form of GC logging. Run java -XX:+PrintFlagsFinal to see all of the flags that your particular version of Java understands.
    – AlBlue
    May 1, 2016 at 22:49
1

As of now, the Kafka's default package has errors with Java 9. The easiest solution is to roll back to java8.

sudo add-apt-repository ppa:webupd8team/java
sudo apt update; sudo apt install oracle-java8-installer
sudo apt install oracle-java8-set-default
2
  • 1
    Kafka works fine with Java 9 and 10. It's just a small error in the version detection part of the script. You should definitely not roll back your Java version just because of this. Jun 12, 2018 at 12:42
  • 1
    This PPA is deprecated. Sep 18, 2019 at 7:43
0

@Mitchell Tracy, i know this is a bit older thread, just putting it out there my findings on the same issue i encountered if anyone's running into same issue.

I had jdk-9 (Early Access) pointing in my $java_home, i got all kinds of errors per se, Unrecognized VM option 'PrintGCDateStamps', -loggc deprecreated, -cp requires a classpath specified, and so forth.

Moved the jdk-9 out of the way from $java_home with a command (sudo mv jdk1.8.0.jdk ~/Documents) and restarted the terminal, It worked like a charm! I was able to fire up zookeeper-server-start and kafka. I hope this helps.

1
  • The same for the JDK 9 release version for me now. Did you create an issue in Kafka etc.?
    – Dmytro
    Sep 27, 2017 at 8:55
0

I am using java 10 and kafka_2.11-0.10.1.0 and I had the same problem.I did not find JAVA_MAJOR_VERSION in the kafka-run-class.sh ,so I reviewed the error. It says "Unrecognized VM option 'PrintGCDateStamps'" This means, Java 10 GC related vm options are changed and Kafka configs are not compatible with it yet. This also confirms my thoughts.

So switching to a Java version < 9 is one solution but if you want to keep using your new java version then instead of removing the whole line containing that parameter , you can remove the specified option. I did that and then "PrintGCTimeStamps" became a problem. I removed that also. So I ended up having the line below : KAFKA_GC_LOG_OPTS="-Xloggc:$LOG_DIR/$GC_LOG_FILE_NAME -verbose:gc -XX:+PrintGCDetails " So this will still print the GC details , but timestamp will not be specified. Zookeeper started without any problem!

-1

I was using windows so I just ran the bat file instead of the shell script

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.