I am trying to compile my project with Java 11.
When I try to run the application with Java 8 as the Java version in pom.xml, it works fine. But when I try to run it
Seems like you're having the JAVA_HOME set in your mvn.bat. It could be pointing to the older version of Java (i.e. 11 in your case).
JAVA_HOME
mvn.bat
set JAVA_HOME=C:\path\to\jdk11 try using it on the first line, before calling maven.
set JAVA_HOME=C:\path\to\jdk11