MAVEN is a project management tool, and if we don't tell it what version of the JDK our code is going to compile with, it will be processed with the default JDK version of Maven-compiler-plugin, which makes it prone to version mismatches. Problems that could lead to a compilation that does not pass. For example, if a new feature of jdk1.7 is used in the code, but Maven uses the version of jdk1.6 when compiling, then this piece of code is completely impossible to compile into a. class file. In order to deal with this situation, when building a MAVEN project, I was accustomed to the first step of configuring the Maven-compiler-plugin plugin.
Let's take a look at how this plugin should be used
<plugin>2<groupId>Org.apache.maven.plugins</groupId>3<Artifactid>Maven-compiler-plugin</Artifactid>4<version>3.1</version>5<Configuration>6<Source>1.6</Source> <!--development version used by source code -7<Target>1.6</Target> <!--the compiled version of the target class file that needs to be generated -8<!--In general , Target is consistent with source, but sometimes in order for the program to run in other versions of the JDK (for the lower version of the target JDK, the source code needs not to use the syntax that is not supported in the lower version of the JDK). There is a situation where target differs from source -9 Ten<!--Here are the options available - One<meminitial>128m</meminitial> A<Maxmem>512m</Maxmem> -<Fork>True</Fork> <!--Fork is enable, which is used to explicitly indicate the availability of a compiled version configuration - -<CompilerVersion>1.3</CompilerVersion> About<!--This option is used to pass parameter options that are not included by the compiler itself but are supported - -<compilerargument>-verbose-bootclasspath ${java.home}\lib\rt.jar</compilerargument> About</Configuration> -</plugin>
It can also be added on the basis of dynamic
<!--Project Properties - <Properties> <Java.compiler>1.6</Java.compiler> <spring.version>3.1.0.RELEASE</spring.version> <mysql.version>5.1.16</mysql.version> </Properties>
< Source >${java.compiler}</source><target> ${java.compiler}</target>
Most of the time, people like to generate webapp maven projects directly in Eclipse, but this can cause a lot of problems, especially when using a JDK that is not the default for MAVEN.
In general, I started by creating a basic MAVEN project (create a simple project) with the following type
Then set up the JDK version and change to
<packaging>war</packaging>
With Eclipse update maven project, Eclipse's Maven plugin will help us set up the various default parameters that this webapp supports under the current JDK, and then we can use it again, which will save a lot of trouble.
MAVEN Series-The use of "Maven-compiler-plugin"