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.