動態修改maven的jdk版本

當環境變量jdk爲1.7,項目爲jdk1.8,用mvn clean package指令打包項目時,想不修改環境變量的狀況下,修改maven的jdk版本html

方法以下:java

官網給出了方法apache

https://maven.apache.org/plugins/maven-compiler-plugin/examples/compile-using-different-jdk.htmlmaven

1.pom.xml中添加maven插件spa

            <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>${JAVA_1_8_HOME}/bin/javac</executable>
                    <compilerVersion>1.8</compilerVersion>
                </configuration>
            </plugin>

2.maven中的settings.xml中添加插件

<profiles>   
   <profile> <id>compiler</id> <properties> <JAVA_1_8_HOME>D:\Program Files (x86)\Java\jdk1.8.0_181</JAVA_1_8_HOME> </properties> </profile>
</profiles>

  <activeProfiles>
  <activeProfile>compiler</activeProfile>
  </activeProfiles>code

<JAVA_1_8_HOME>D:\Program Files (x86)\Java\jdk1.8.0_181</JAVA_1_8_HOME> 爲jdk的地址
相關文章
相關標籤/搜索