1. Problem description
A new Maven project was created in Eclipse, and then the JDK version was changed to 1.7. As a result, the JDK version was restored to 1.5 every time you use Maven > Update project.
2. Cause analysis
The official Maven document is described as follows:
Compiler plug-in is used to compile the source files of the project. Starting from version 3.0, the default compiler used to compile Java source files is javax.tools.JavaCompiler (if you are using java 1.6). If you want to force the plug-in to use javac, you must configure the plug-in option forceJavacCompilerUse. It should be noted that the default settings for the current source option and target option are 1.5, which has nothing to do with the JDK version when running Maven. If you want to change these default settings, you can refer to the description in Setting the -source and -target of the Java Compiler to set the source and target options.
This is a feature known to Maven. Unless a specified version is displayed in your POM file, the compiler default source/target version 1.5 will be used. The main reason is that the integration method of Maven in Eclipse plays a key role. It will generate the project's .project, .classpath and .settings from the POM file. Therefore, unless the POM file specifies the correct JDK version, it will reset to version 1.5 every time you update the project configuration.
3. Solution
Add the following configuration to the pom.xml file:
<plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-compiler-plugin</artifactId> <version>2.3.2</version> <configuration> <source>1.7</source> <target>1.7</target> <encoding>UTF-8</encoding> </configuration> </plugin> </plugins>
As shown in the picture:
Re-Maven > Update project again, and the problem can be solved.
The above is all the contents of the problem that the project jdk becomes 1.5 after the maven update project has been solved. I hope everyone will support Wulin.com more~