Reputation: 120
I am facing the error, when compiling and running java in NetBeans 12 for Spring Boot 3.0.3 & Java 17.
java.lang.UnsupportedClassVersionError: com/example/javareacttemplate/MainClass has been compiled by a more recent version of the Java Runtime (class file version 61.0), this version of the Java Runtime only recognizes class file versions up to 52.0
I was trying to create a simple maven project to print the Java runtime version next to that project and it successfully ran with the output:
System.out.println("Java v:" + System.getProperty("java.version"));
//Java v:17.0.6
And these are 2 terminal commands at the beginning of running 2 projects
The Spring Boot one
cd D:\somepath\somepath\projectOne;
"JAVA_HOME=D:\\Program Files\\Java\\jdk-17"
M2_HOME=D:\\Maven\\apache-maven-3.9.0 cmd /c "\"D:\\Maven\\apache-maven-3.9.0\\bin\\mvn.cmd\"
-Dexec.args=\"-classpath %classpath com.example.javareacttemplate.MainClass\"
-Dexec.executable=java
-Dexec.classpathScope=runtime
-Dmaven.ext.class.path=\"C:\\Program Files\\NetBeans-12.0\\netbeans\\java\\maven-nblib\\netbeans-eventspy.jar\"
-Dfile.encoding=UTF-8 org.codehaus.mojo:exec-maven-plugin:1.5.0:exec"
The simple Maven project
cd D:\somepath\somepath\somepath\mavenproject1;
"JAVA_HOME=D:\\Program Files\\Java\\jdk-17"
M2_HOME=D:\\Maven\\apache-maven-3.9.0 cmd /c "\"D:\\Maven\\apache-maven-3.9.0\\bin\\mvn.cmd\"
-Dexec.args=\"-classpath %classpath com.mycompany.mavenproject1.MainClass\"
-Dexec.executable=\"D:\\Program Files\\Java\\jdk-17\\bin\\java.exe\"
-Dexec.classpathScope=runtime
-Dmaven.ext.class.path=\"C:\\Program Files\\NetBeans-12.0\\netbeans\\java\\maven-nblib\\netbeans-eventspy.jar\"
-Dfile.encoding=UTF-8 org.codehaus.mojo:exec-maven-plugin:1.5.0:exec"
I don't know how to change the Spring Boot Java run time, is there any way possible to change it to 17 but still use NetBeans IDE?
Upvotes: 0
Views: 989
Reputation: 120
I have resolved this problem by choosing JAR Packaging instead of WAR at the beginning of Spring Initializr.
Upvotes: 0