How to package with a specific JDK version in Maven.

To set a specific JDK version for packaging in Maven, you can achieve this by configuring the maven-compiler-plugin plugin in the pom.xml file.

First, add the following configuration code in the pom.xml file:

<properties>
   <maven.compiler.source>1.8</maven.compiler.source>
   <maven.compiler.target>1.8</maven.compiler.target>
</properties>

This will specify Maven to compile using Java version 1.8.

Next, add the following code to the configuration of the maven-compiler-plugin plugin.

<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>

This will ensure that Maven compiles and packages using version 1.8 of Java.

Finally, when running the packaging command for Maven (such as mvn clean package), Maven will use the specified JDK version for packaging.

bannerAds