That is a typical scenario when we are using maven and refers to a problem with its configuration.
Your JAVA_HOME environment variable or your IDE are pointing to a JRE rather than a JDK. In this case it is neccesary to set the correct path of your Java JDK.
There are several ways to do that and configure maven correctly:
Maven looks at the JAVA_HOME environment variable to use the rigth JAVA compiler. Therefore, you need to check the path configured in this variable since must refer to a JDK (JAVA Development Kit) and not a JRE (Java Runtime Environment).
To verify that, you can type in the command line:
If It isn’t pointing to a JDK, you can update the value in the following ways:
- Go to System properties > Advanced system settings > Advanced > environment variable and on the System variables section select the JAVA_HOME variable and click on EDIT.
- Write the absolute path to the JDK.
- Command Line On Windows
You can set the variable before running the build as following
- Command Line On Linux
- Click on Windows > Preferences > Java > Installed JREs
- Verify the correct JDK path selected.
Another way is use the maven-compiler-plugin in your project adding it in the pom.xml. In the tag executable you have to set the full path to the correct JAVA JDK.