Maven projects come with a bunch of plugins applied implicitly to the build. One of them being the maven-compiler-plugin
. Unfortunately the Java version for the plugin defaults to 1.5. Most Maven project you see will override the Java version simply by declaring the plugin (in your pom.xml file) and configuring the Java version
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
</plugins>
</build>
Eclipse (with m2e plugin) will set the compiler compliance level to the setting in the plugin. You can view this by going to
Right click on the project -> properties -> Java Compiler -> Look at compliance level
UPDATE
Instead of the above compiler plugin configuration, you can also simply just do
<properties>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
</properties>
The default plugin configuration will look for these properties. It's a lot less verbose than re-declaring the plugin.
After adding the properties or the compiler plugin to your pom.xml, you might need to update the project. See Manish's answer.
<plugins>
If you don't see it, you can and it. Just google maven-compiler-plugin. It not difficult to add. After you add it, update the project – Paul Samsotha</version>
add<configuration><source>1.8</source><target>1.8</target></configuration>
, then Right click project -> Maven -> Update Project – Paul Samsotha