How to specify the jdk version in maven and jdk version in maven
Problem reproduction:
When we create a maven project, the default jdk version is 1.5, and we usually install a version later than 1.7 on the machine. The jdk version is different. This problem occurs, there are two solutions:
It is not recommended to set the jdk version by right-clicking, because the updated project of this right-clicking setting is changed back to the original jdk version. It means being busy ....
Solution: solution 1: (one configuration, permanent use, recommended)
Copy the path to settings. xml and add the following code between <profiles> </profiles>. :
<profile> <id>jdk-1.8</id> <activation> <activeByDefault>true</activeByDefault> <jdk>1.8</jdk> </activation> <properties> <maven.compiler.source>1.8</maven.compiler.source> <maven.compiler.target>1.8</maven.compiler.target> <maven.compiler.compilerVersion>1.8</maven.compiler.compilerVersion> </properties> </profile>
Second: (local configuration)
Add the following code to the project pom. xml file:
<Build> <plugins> <! -- Specify jdk 1.8 --> <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>