简体   繁体   中英

How to specify java version when I use mvn package command without change environment path

My environment java version is jdk8,Now I want use Maven command mvn package to compile some project.How to specify java version(like java11) to compile it whitout change environment path,because java version is a dynamic arguments in my process

In pom.xml you can define the version of JDK

Like

<properties>
    <java.version>1.8</java.version>
    <spring-cloud.version>2020.0.1</spring-cloud.version>
</properties>

Compiling Sources Using A Different JDK

    <project>
      [...]
      <build>
        [...]
        <plugins>
          <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <version>3.8.1</version>
            <configuration>
              <verbose>true</verbose>
              <fork>true</fork>
              <executable><!-- path-to-javac --></executable>
              <compilerVersion>11</compilerVersion>
            </configuration>
          </plugin>
        </plugins>
        [...]
      </build>
      [...]
    </project>

Well the side effect is we have to edit the pom.xml file.

  • We may keep different version of pom.xml file, like pom-java11.xml , pom-java17.xml
  • mvn -f <other pom file> for your task, like mvn -f pom-java11.xml...

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM