I imported a Maven project and it used Java 1.5 even though I have 1.6 configured as my Eclipse default Preferences->Java->Installed JREs
.
When I
To change JDK's version, you can do:
1- Project > Properties
2- Go to Java Build Path
3- In Libraries, select JRE System ... and click on Edit
4- Choose your appropriate version and validate
The m2eclipse plugin doesn't use Eclipse defaults, the m2eclipse plugin derives the settings from the POM. So if you want a Maven project to be configured to use Java 1.6 settings when imported under Eclipse, configure the maven-compiler-plugin
appropriately, as I already suggested:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.1</version>
<configuration>
<source>1.6</source>
<target>1.6</target>
</configuration>
</plugin>
If your project is already imported, update the project configuration (right-click on the project then Maven V Update Project Configuration).
One more place where this can go wrong is in the project specific settings, in Eclipse.
project properties: click your project and one of the following:
click on "Java Compiler"
Because of client requirements we had them enabled to keep our projects in 1.6. When it was needed to upgrade to 1.7, we had a hard time because we needed to change the java version all over the place:
In case anyone's wondering why Eclipse still puts a J2SE-1.5 library on the Java Build Path in a Maven project even if a Java version >= 9 is specified by the maven.compiler.release
property (as of October 2020, that is Eclipse version 2020-09 including Maven version 3.6.3): Maven by default uses version 3.1 of the Maven compiler plugin, while the release property has been introduced only in version 3.6.
So don't forget to include a current version of the Maven compiler plugin in your pom.xml when using the release property:
<properties>
<maven.compiler.release>15</maven.compiler.release>
</properties>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
</plugin>
</plugins>
</build>
Or alternatively but possibly less prominent, specify the Java version directly in the plugin configuration:
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
<configuration>
<release>15</release>
</configuration>
</plugin>
</plugins>
</build>
This picks up Line's comment on the accepted answer which, had I seen it earlier, would have saved me another hour of searching.
I found that my issue was someone committed the file .project and .classpath that had references to Java1.5 as the default JRE.
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/J2SE-1.5">
<attributes>
<attribute name="owner.project.facets" value="java"/>
</attributes>
</classpathentry>
By closing the project, removing the files, and then re-importing as a Maven project, I was able to properly set the project to use workspace JRE or the relevant jdk without it reverting back to 1.5 . Thus, avoid checking into your SVN the .project and .classpath files
Hope this helps others.
Simplest solution in Springboot
I'll give you the most simpler one if you use Springboot:
<properties>
<java.version>1.8</java.version>
</properties>
Then, right click on your Eclipse project: Maven > Update project > Update project configuration from pom.xml
That should do.