Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Apache JMeter: Error: Java version is too low to run JMeter

Tags:

macos

jmeter

The JMeter always shows:

$ sh jmeter
Error: Java version is too low to run JMeter. Needs at least Java >= 1.8.0.

But I got the java version in terminal as:

$ java -version
java version "9.0.1"
Java(TM) SE Runtime Environment (build 9.0.1+11)
Java HotSpot(TM) 64-Bit Server VM (build 9.0.1+11, mixed mode)

What's the right way for me? The newest JAVA SDK should be here.

Environments:
macOS High Sierra 10.13.1
apache-jmeter-3.3
like image 619
Raniys Avatar asked Nov 08 '17 13:11

Raniys


2 Answers

JMeter executable bin/jmeter is a shell script, you can modify it as you like.. you can skip the Java version check totally. I am talking about older JMeter version like 2 or 3. Now for 5.4.1, maybe for 4 and 5, it will consider JAVA_HOME properly without my fix here.

Or, if you don't want to remove so much code, here's a way to take JAVA_HOME into consideration.

Apparently, this paragraph below does not do the its work right:

MINIMAL_VERSION=1.6.0

# Check if Java is present and the minimal version requierement
_java=`type java | awk '{ print $ NF }'`   # <<<<<<<<<<< here is the problem
CURRENT_VERSION=`"$_java" -version 2>&1 | awk -F'"' '/version/ {print $2}'`
minimal_version=`echo $MINIMAL_VERSION | awk -F'.' '{ print $2 }'`
current_version=`echo $CURRENT_VERSION | awk -F'.' '{ print $2 }'`
if [ $current_version ]; then
    if [ $current_version -lt $minimal_version ]; then
             echo "Error: Java version is too low to run JMeter. Needs at least Java >= ${MINIMAL_VERSION}." 
             exit 1
    fi
else
     echo "Not able to find Java executable or version. Please check your Java installation."
     exit 1
fi

I have Java 11 and Java 8 both installed, and java -version will use Java 11. So CURRENT_VERSION will print 11.0.11 and does not pass the check, because the code will compare 0 with 6, but actually it should compare 11.0 with 1.6. It is a great compatibility issue with Java 11 version naming, I would say; I mean, I had problem with it when Java 9 comes out, too.

I think it should take into consideration the JAVA_HOME env variable, as Maven does. For Maven I can create alias like mvn8 to set JAVA_HOME first and run, so it will use the Java executable in that. Similarly I have mvn11 as another alias.

$ alias mvn8
alias mvn8='JAVA_HOME=/usr/lib/jvm/java-8-openjdk-amd64 mvn -Dstyle.color=auto'

I want to do the same to jmeter, so I changed this line

_java=`type java | awk '{ print $ NF }'`

to:

# Check if Java is present and the minimal version requirement, taking into consideration `$JAVA_HOME`
if [ -z $JAVA_HOME ] ; then 
    echo JAVA_HOME not set, will check java version without it
    _java=`type java | awk '{ print $ NF }'`
else
    _java=`type $JAVA_HOME/bin/java | awk '{ print $ NF }'`
fi

And I define an alias for it, too:

alias jmeter8='JAVA_HOME=/usr/lib/jvm/java-8-openjdk-amd64 /opt/apache-jmeter-2.13/bin/jmeter'

So that it will always use Java 8.

like image 51
WesternGun Avatar answered Dec 07 '22 12:12

WesternGun


According to the bug 61529 Java 9 support will be added in the next release.

See JMeter Release Notes and What's New in JMeter 3.3? for more details.

You should have previous Java versions under /Library/Java/JavaVirtualMachines/ folder, try using Java 8 from there. If you cannot for some reason try the following alternative approaches:

  • Run JMeter as java -jar ApacheJMeter.jar instead of running the shell script
  • Try nightly build of JMeter, it might be the case the issue is already fixed in it.
like image 39
Dmitri T Avatar answered Dec 07 '22 13:12

Dmitri T