Monday, July 3, 2023

Intellij JAVA_HOME environment variable is not defined correctly when running mvn

 If you get an error:

C:\>mvn -version
The JAVA_HOME environment variable is not defined correctly
This environment variable is needed to run this program 

NB: JAVA_HOME should point to a JDK not a JRE 


One option is to ensure your pom.xml file has the java details


In the example below, using OpenJDK version 20 which is located C:\Program Files\Java\jdk-20\bin

In Intellij 2023 1.3, you can verify the "20" under File>Project Structure>SDK

<properties>
<maven.compiler.source>20</maven.compiler.source>
<maven.compiler.target>20</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>