Search code examples
javaspring-bootspring-tool-suitestsspring-tools-4

compiling with java17 even though compiler compliance pointed to java8 in spring tool suite 4


I have downloaded Spring Tool Suite4 IDE, Java17 Came Along with that IDE. But i want to work on Java8.

I installed only java8 in my system and started working on to print just "Hello Spring Boot".

When i run the sample project the code is being compiled with java17 and trying to run with java8(which i have given in execution environments and build path)

I got error like below.

Exception in thread "main" java.lang.UnsupportedClassVersionError: org/springframework/boot/SpringApplication 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

at java.lang.ClassLoader.defineClass1(Native Method)

at java.lang.ClassLoader.defineClass(ClassLoader.java:756)

at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)

at java.net.URLClassLoader.defineClass(URLClassLoader.java:473)

at java.net.URLClassLoader.access$100(URLClassLoader.java:74)

at java.net.URLClassLoader$1.run(URLClassLoader.java:369)

at java.net.URLClassLoader$1.run(URLClassLoader.java:363)

at java.security.AccessController.doPrivileged(Native Method)

at java.net.URLClassLoader.findClass(URLClassLoader.java:362)

at java.lang.ClassLoader.loadClass(ClassLoader.java:418)

at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:355)

at java.lang.ClassLoader.loadClass(ClassLoader.java:351)

at com.aditya.springboot.HelloSpringBootProjectApplication.main(HelloSpringBootProjectApplication.java:10)

I changed the compiler compliance from 17 to 1.8 in windows-\>preferences-\>Compiler-\>JDK Compliance..,

I pointed the Installed JREs to from jre 17(default) to jdk 1.8 and

I changed the compiler compliance from 17 to 1.8 in project-\>properties-\>java compiler also.

I tried uninstalling the STS4 and reinstalling it, but still i am getting same error.

As i am using maven project i tried changing \<java.version\> to 1.8 from 17 in pom.xml file too.

Can anyone help me from where STS is taking java17 inorder to compile my code, i haven't installed java17 in my system also. I have pointed JAVA_HOME in enviroment variables(user level variable but not system level varaiable) to java8 only.


Solution

  • I found an answer

    The problem is with java version in pom.xml file of Maven: If i am creating a maven project with spring boot version 3+, pom.xml is taking java version as 17 by default. Even if we change the version to 1.8 in pom.xml it is showing error as version mismatch because pom.xml internally taking java17. When i changed the java version to 9 in pom.xml it compiled and ran successfully. so we need to use java9+ for spring boot 3+.

    But still i want to use java 1.8 for project so i degraded springboot version: For creating the same maven project i used spring boot version 2+(i.e 2.7.8). Now maven by default took 1.8 version with out giving chance for us to modify. My project ran with 1.8 successfully.