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:

  1. Open the pom.xml file of the project.
  2. Locate the build node in the pom.xml file and create one if it does not exist.
  3. Under the build node, locate the plugins node and create one if it does not exist.
  4. Add the maven-compiler-plugin plugin under the plugins node.
  5. 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>
  1. Save the pom.xml file.

During the process above, a specific JDK version will be used for compiling when packaging a project using Maven.

bannerAds