How do you specify the Java compiler version in a pom.xml file?

Method 1: If you want to use the Java 8 language features (-source 1.8) and also want the compiled classes to be compatible with JVM 1.8 (-target 1.8), you can either add the two following properties, which are the default property names for the plugin parameters:

 <project>    [...]     <properties>         <maven.compiler.source>1.8</maven.compiler.source>         <>1.8</>     </properties>   [...] </project>

Method 2: Add below details inside pom.xml file.

<project>  [...]  <build>    [...]    <plugins>      <plugin>        <groupId>org.apache.maven.plugins</groupId>        <artifactId>maven-compiler-plugin</artifactId>        <version>(whatever version is current)</version>        <configuration>          <!-- or whatever version you use -->          <source>1.7</source>          <target>1.7</target>        </configuration>      </plugin>    </plugins>    [...]  </build>  [...]</project>

After right click on project > Maven > update project (checked force update)

It will  resolve your  error on project

Always use Java Version 1.8 or 1.9 or the latest one.

Hope it’s will helpful.