How to specify the JDK version for Maven packaging?
To specify the JDK version in Maven, you can achieve this by adding the maven-compiler-plugin in the plugins section under the build node in the pom.xml file. The specific steps are as follows:
- Open the pom.xml file of the project.
- Locate the build node in the pom.xml file and create one if it does not exist.
- Under the build node, locate the plugins node and create one if it does not exist.
- Add the maven-compiler-plugin plugin under the plugins node.
- Under the configuration node in the maven-compiler-plugin plugin, add source and target nodes, and specify the corresponding JDK version. For example, specify JDK version as 1.8.
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
</plugins>
</build>
- Save the pom.xml file.
During the process above, a specific JDK version will be used for compiling when packaging a project using Maven.