How to set the Java compiler version in the Maven Pom.xml file

Source: Internet
Author: User

There is a problem today:

When you create a new Web project with Maven in Eclipse and then update it with MAVEN, the JDK version automatically becomes 1.5.

By finding the data, we finally found the following explanation in the documentation for the MAVEN compiler plugin (maven Compiler Plugin):

The Compiler Plugin is used to compile the sources of your project. Since 3.0, the default compiler is Javax.tools.JavaCompiler (if you were using Java 1.6) and is used to compile Java source S. If you want to force the plugin using javac, you must configure the plugin option Forcejavaccompileruse.

Also note that at PR esent The default source setting is 1.5 and the default target setting is 1.5, Ind Ependently of the JDK you run Maven with. If you want to change these defaults, you should set source and target as described in Setting the-sour Ce And-target of the Java Compiler.

There are two ways to set the compiler version. Here is the code snippet for the Pom.xml file:

The first method:

<Project>    <Properties>        <Maven.compiler.source>1.8</Maven.compiler.source>        <Maven.compiler.target>1.8</Maven.compiler.target>    </Properties></Project>

The second method:

<Project>    <Build>    <Plugins>        <plugin>        <groupId>Org.apache.maven.plugins</groupId>        <Artifactid>Maven-compiler-plugin</Artifactid>        <version>3.7.0</version>        <Configuration>            <Source>1.8</Source>            <Target>1.8</Target>        </Configuration>        </plugin>    </Plugins>    </Build></Project>

Finally, right-click on the project in Eclipse and re-update the project with MAVEN.

How to set the Java compiler version in the Maven Pom.xml file

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.