Java modifies the default jdk version of maven to 1.7, and mavenjdk

Source: Internet
Author: User

Java modifies the default jdk version of maven to 1.7, and mavenjdk

Java modifies the default jdk version of maven.

 

Problem:

1. When creating a maven project, the jdk version is 1.5, and the installed version is 1.7 or 1.8.

2. Each time you right-click the project name-maven-> update project, the jdk version of the project changes to version 1.5 or another version.

 

Solution:

Solution 1: In the project, specify the jdk version in pom. xml, as follows:

<build>          <plugins>              <plugin>                  <groupId>org.apache.maven.plugins</groupId>                  <artifactId>maven-compiler-plugin</artifactId>                  <version>3.1</version>                  <configuration>                      <source>1.7</source>                      <target>1.7</target>                  </configuration>              </plugin>          </plugins>      </build>

  

This method can only ensure that the project is jdk1.7. Each time you create a project, you must add the Code. This method is not recommended. The second method is recommended.

 

Solution 2: Find the settings. xml file in the maven installation directory and add the following code

 

<profile>        <id>jdk-1.7</id>         <activation>              <activeByDefault>true</activeByDefault>              <jdk>1.7</jdk>          </activation>    <properties>    <maven.compiler.source>1.7</maven.compiler.source>    <maven.compiler.target>1.7</maven.compiler.target>    <maven.compiler.compilerVersion>1.7</maven.compiler.compilerVersion>    </properties> </profile>

  

After adding, set eclipse. Window-> preferences-> maven-> user settings, select the settings. xml file under the maven installation directory in user settings. For example

After the configuration is complete, right-click the project-> maven-> update project, so that jdk1.8 is used by default for each maven project created.

Solution 3:

In solution 2, the default settigs. xml file path of user settings is c: \ users \ Hxinguan \. m2 \ settings. xml, as shown in. Just copy the configured settings. xml file to the directory and update the project.

 

 

 

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.