diff --git a/pom.xml b/pom.xml
index 96c4337..371fb69 100644
--- a/pom.xml
+++ b/pom.xml
@@ -70,6 +70,7 @@ under the License.
8
3.9.15
2024-04-18T00:34:08Z
+ ${env.JAVA_HOME}
diff --git a/src/it/select-jdk-env-multi/invoker.properties b/src/it/select-jdk-env-multi/invoker.properties
new file mode 100644
index 0000000..9d5da15
--- /dev/null
+++ b/src/it/select-jdk-env-multi/invoker.properties
@@ -0,0 +1,20 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements. See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership. The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied. See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+invoker.goals = compile
+invoker.environmentVariables.JAVA_X_HOME = ${JAVA_HOME}
+invoker.environmentVariables.JAVA_Y_HOME = ${JAVA_HOME}
diff --git a/src/it/select-jdk-env-multi/pom.xml b/src/it/select-jdk-env-multi/pom.xml
new file mode 100644
index 0000000..a2b0b49
--- /dev/null
+++ b/src/it/select-jdk-env-multi/pom.xml
@@ -0,0 +1,54 @@
+
+
+
+ 4.0.0
+
+ org.apache.maven.plugins.toolchains.its
+ select-jdk-env-multi
+ 1.0-SNAPSHOT
+ jar
+
+ maven-toolchains-plugin IT: select jdk toolchain test with environment variable
+ Check that jdk toolchain can be selected when multiple environment variables are used
+
+
+ UTF-8
+
+
+
+
+
+ org.apache.maven.plugins
+ maven-toolchains-plugin
+ @project.version@
+
+ JAVA_X_HOME
+
+
+
+
+ select-jdk-toolchain
+
+
+
+
+
+
+
diff --git a/src/main/java/org/apache/maven/plugins/toolchain/jdk/SelectJdkToolchainMojo.java b/src/main/java/org/apache/maven/plugins/toolchain/jdk/SelectJdkToolchainMojo.java
index 77a79a1..70a6c2b 100644
--- a/src/main/java/org/apache/maven/plugins/toolchain/jdk/SelectJdkToolchainMojo.java
+++ b/src/main/java/org/apache/maven/plugins/toolchain/jdk/SelectJdkToolchainMojo.java
@@ -255,7 +255,7 @@ private boolean matches(String key, String reqVal, String tcVal) {
case VERSION:
return RequirementMatcherFactory.createVersionMatcher(tcVal).matches(reqVal);
case ENV:
- return reqVal.matches("(.*,|^)\\Q" + tcVal + "\\E(,.*|$)");
+ return tcVal.matches("(.*,|^)\\Q" + reqVal + "\\E(,.*|$)");
default:
return RequirementMatcherFactory.createExactMatcher(tcVal).matches(reqVal);
}