Apache Kafka 2.12-1.1.0 not working with JDK -10.0.1 - apache-kafka

Why doesn't Apache Kafka 2.12-1.1.0 work with JDK 10.0.1?
./bin/zookeeper-server-start.sh config/zookeeper.properties
java version "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)
/..../kafka_2.12-1.1.0/bin/kafka-run-class.sh: line 252: [[: 10 2018-04-17: syntax error in expression (error token is "2018-04-17")
[0.000s][warning][gc] -Xloggc is deprecated. Will use -Xlog:gc:/..../kafka_2.12-1.1.0/bin/../logs/zookeeper-gc.log instead.
Unrecognized VM option 'PrintGCDateStamps'
Error: Could not create the Java Virtual Machine.
Error: A fatal exception has occurred. Program will exit.

Changing the bin/kafka-run-class.sh with below code did the magic:
In Line #251
Before:
JAVA_MAJOR_VERSION=$($JAVA -version 2>&1 | sed -E -n 's/.* version "([^.-]*).*"/\1/p')
After:
JAVA_MAJOR_VERSION=$($JAVA -version 2>&1 | sed -E -n 's/.* version "([^.-]*).*/\1/p')

You can remove the offending logging option KAFKA_GC_LOG_OPTS for java 10 from the file kafka-run-class.sh
from
KAFKA_GC_LOG_OPTS="-Xloggc:$LOG_DIR/$GC_LOG_FILE_NAME -verbose:gc -XX:+PrintGCDetails -XX:+PrintGCDateStamps -XX:+PrintGCTimeStamps -XX:+UseGCLogFileRotation -XX:NumberOfGCLogFiles=10 -XX:GCLogFileSize=100M"
to
KAFKA_GC_LOG_OPTS="-Xloggc:$LOG_DIR/$GC_LOG_FILE_NAME -verbose:gc -XX:+PrintGCDetails"

JAVA_MAJOR_VERSION=$($JAVA -version 2>&1 | sed -E -n 's/.* version
"([0-9]).$/\1/p')
This line solved my problem with openjdk!
This is the original line from bin/kafka-run-class.sh that you need replace:
JAVA_MAJOR_VERSION=$($JAVA -version 2>&1 | sed -E -n 's/.* version
"([^.-])."/\1/p')

There is a problem in the regex used for identifying the java version in the bin/kafka-run-class.sh especially if you are using openjdk.
You can replace line 255 in the bin/kafka-run-class.sh with :
JAVA_MAJOR_VERSION=$($JAVA -version 2>&1 | sed -E -n 's/.* version "([0-9]*).*$/\1/p')
as in https://github.com/apache/kafka/blob/trunk/bin/kafka-run-class.sh#L286

Above all answers are from the shell script point of view. If some people are using a bat file on the windows machine below answer will be helpful.
Windows Bat file
Go to ..\kafka_2.12-2.2.0\bin\windows and search for kafka-run-class.bat file
Go to Line Number 158 and set the JDK Path.
IF ["%JAVA_HOME%"] EQU [""] (
set JAVA=java
) ELSE (
set JAVA="..\Java\jdk12\bin\java"
)
Shell Script
Go to ..\kafka_2.12-2.2.0\bin\ and search for kafka-run-class.sh file.
and then search for $JAVA_HOME and go this line update your JDK path accordingly.
if [ -z "$JAVA_HOME" ]; then
JAVA="java"
else
JAVA="$JAVA_HOME\java"
fi
JAVA = "../Java/jdk12/bin/java"
echo $JAVA
I think this will address the issue. This will occur when we have multiple JDK installed on our machine and want to test the things.

I removed the tags like PrintGCDateStamps,UseGCLogFileRotation from line 314

Related

Having issues running the result of an Xargs find to get version of found items

I'm able to return the path to the java executable but what i really want is the version of java so want to run the path returned with -version attached to the end.
Any help appreciated.
locate -b '\java' | xargs -ri find {} -prune -type f -executable
Thanks
Here was the eventual answer.
locate -b '\java' | xargs -ri find {} -prune -type f -executable | xargs bash -c '$0 -version'
java version "1.6.0_41"
OpenJDK Runtime Environment (IcedTea6 1.13.13) (rhel-1.13.13.1.el6_8-x86_64)
OpenJDK 64-Bit Server VM (build 23.41-b41, mixed mode)```

sed code works in 4.2.1 but not 4.1.5

I have the following sed code that works in RH6 and sed 4.2.1
>> echo "SUSE Linux Enterprise Server 11 ( x86_64 ) VERSION = 11 PATCHLEVEL = 2" | sed s/.*VERSION\ =\ //
11 PATCHLEVEL = 2
>> sed --version
GNU sed version 4.2.1
but it fails at SUSE 11 and sed 4.1.5
>> echo "SUSE Linux Enterprise Server 11 ( x86_64 ) VERSION = 11 PATCHLEVEL = 2" | sed s/.*VERSION\ =\ //
sed: No match.
>> sed --version
GNU sed version 4.1.5
I found the following code works differently in the two versions. sed 4.1.5 in SUSE cannot match anything.
echo ab | sed s/.*//
Is it a known issue of sed? and does it have a solution?
Since you didn't quote the asterisk, your shell is trying to glob it. On one of your systems this globbing fails and the original string is returned. On your other system it matches something and your substitution regex is destroyed. Always quote arguments that the shell might consider "special".
I found sed 4.1.5 needs single quotes to make things work. The following works.
echo ab | sed 's/.*//'
But the sed 4.2.1 does not need this.

Batch file to check the minimum required Java version

I'm new to batch script coding and a little stuck here. I've got a .sh file that checks if version of java installed is at least 1.8.0:
# Minimal version
MINIMAL_VERSION=1.8.0
# Check if Java is present and the minimal version requirement
_java=`type java | awk '{ print $ NF }'`
CURRENT_VERSION=`"$_java" -version 2>&1 | awk -F'"' '/version/ {print $2}'` #says 1.8.0_65
minimal_version=`echo $MINIMAL_VERSION | awk -F'.' '{ print $2 }'` #says 8
current_version=`echo $CURRENT_VERSION | awk -F'.' '{ print $2 }'` #says 8
if [ $current_version ]; then
if [ $current_version -lt $minimal_version ]; then
echo "Error: Java version is too low. At least Java >= ${MINIMAL_VERSION} needed.";
exit 1;
fi
else
echo "Not able to find Java executable or version. Please check your Java installation.";
exit 1;
fi
It is pretty clear. I need to write a .bat file for Windows exactly same logic. So here's where I'm stuck, because I do not know windows analogs for awk.
Here you can see how you can get java version like integer which can numerically compared:
#echo off
:: uncomment the line bellow if the java.exe is not in the %PATH%
::PATH %PATH%;%JAVA_HOME%\bin\
java -version 1>nul 2>nul || (
echo no java installed
exit /b 2
)
for /f tokens^=2-5^ delims^=.-_^" %%j in ('java -fullversion 2^>^&1') do set "jver=%%j%%k%%l%%m"
if %jver% LSS 18000 (
echo java version is too low
echo at least 1.8 is needed
exit /b 1
)

How to find out which Play version I'm using?

Kinda silly question, but I used Activator to get started with the play framework, and now need to see what version I'm using. 2.3 came out with support for docker, but when I put
dockerExposedPorts in Docker := Seq(9000, 9443)
in my build.sbt, it complains it doesn't know what dockerExposedPorts is, so I'm thinking I might be running 2.2.
Type playVersion within the activator console.
Alternatively you can look in project/plugins.sbt for the line
addSbtPlugin("com.typesafe.play" % "sbt-plugin" % "2.3.2")
In this example, the play version is 2.3.2
I use the following to list and highlight all play versions in a play project. Works for a multi-module project as well.
The following was tested on macOS Sierra using the default BSD find that it comes with and GNU grep installed via brew install grep. The latter is required since the following command requires a grep that supports Perl regex (which BSD grep does not).
You can check if the grep on your PATH has Perl-regex support by doing this (should show that the -P option is available):
$ ggrep --help | grep -i Perl
-P, --perl-regexp PATTERN is a Perl regular expression
(ggrep is the GNU grep installed via Homebrew)
And now, on to the actual command (note the ggrep in the command):
$ find . -name "plugins.sbt" -exec ggrep -PHin --color=always 'com.typesafe.play.*sbt-plugin.*%\s*"\K.*?(?=")' {} \;
which outputs:
Quick notes about the grep options (extracted from grep help):
-P, --perl-regexp PATTERN is a Perl regular expression
-i, --ignore-case ignore case distinctions
-n, --line-number print line number with output lines
-H, --with-filename print file name with output lines

Is there something wrong with sed for the mac terminal?

I am having trouble making sed work on my mac terminal. The original version I have is /usr/bin/sed
I want to see what version it is so I type:
sed --version
I get the following output:
/usr/bin/sed: illegal option -- - usage: sed script [-Ealn] [-i
extension] [file ...]
sed [-Ealn] [-i extension] [-e script] ... [-f script_file] ... [file ...]
My man page is for sed 4.2 and that should have a --version option
I then installed to /usr/local/bin by downloading from gnu ftp http://ftp.gnu.org/gnu/sed/
I then run /usr/local/bin/sed --version and still get same output as with original version. I am completely confused, can anyone figure out what I am doing wrong?
EDIT: It seems like even though which sed gives me /usr/local/bin/sed the command sed is still running /usr/bin/sed, consequently /usr/local/bin/sed is not being invoked. If I invoke with full path it works as expected.
I guess question is now why which sed is giving me /usr/local/bin/sed yet the command run when I type sed is /usr/bin/sed
Your /usr/bin/sed is the BSD sed which does not support --version as your error statement shows. The man page for it is /usr/share/man/man1/sed.1.gz, when I read that there is no mention of a version at all, however the date on the man page is May 10, 2005.
I am thinking you have an incorrect man page. Most probably a MANPATH that is looking somewhere else first.
As for why /usr/local/bin/sed which you are saying is GNU sed does not honor the --version I am not sure about. Can you give more detail about this?