'Jmeter - How to set Jmeter to pick up specific Java version (windows)

My windows system has two Java versions: 15 & 17

I want to make Jmeter pick up version 15.

I set path as: C:\Program Files\Java\jdk-15.0.2\bin

And JAVA_HOME as C:\Program Files\Java\jdk-15.0.2

When I do: java -version I have:

enter image description here

But still seems like Jmeter is picking up Java 17 due to an exception when I run code that contains JSR223 Assertion

2022-05-12 13:40:51,300 ERROR o.a.j.a.JSR223Assertion: Problem in JSR223 script: JSR223 Assertion
javax.script.ScriptException: org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed:
General error during conversion: Unsupported class file major version 61

How to 'force' Jmeter to pick up java 15?



Solution 1:[1]

It's sufficient to set the Java version you want to use to be ahead of other Javas in PATH environment variable and JMeter will pick it up.

set PATH="C:\Program Files\Java\jdk-15.0.2\bin";%PATH%

In order to check what Java version JMeter is using you can add a Debug Sampler configured like:

enter image description here

and look for java.version property in the View Results Tree listener

enter image description here

or just look for java.version line in the JMeter.log file

enter image description here

Solution 2:[2]

Milk and honey for me here were:

1 set path as: set PATH="C:\Program Files\Java\jdk-15.0.2\bin";%PATH%

2 lunch Jmeter from cmd as: java -jar ApacheJMeter.jar

coz launching from 'ApacheJMeter.jar' probably initiated hardcode java version

the alternative is the creation of .bat launcher as:

a) create startJmeter.bat

b) put inside

c: 
cd C:\apache-jmeter-5.4.3\bin
java -jar ApacheJMeter.jar

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Dmitri T
Solution 2 vlatko606