最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

maven在settings.xml和pom.xml中指定jdk版本編譯的方法

 更新時間:2024年05月08日 10:58:25   作者:kfepiza  
在開發(fā)Java應(yīng)用時,通常需要指定要使用的Java版本,下面這篇文章主要給大家介紹了關(guān)于maven在settings.xm和pom.xml中指定jdk版本編譯的方法,文中通過代碼介紹的非常詳細,需要的朋友可以參考下

maven的settings.xm和pom.xml都可以通過 maven.compiler.source , maven.compiler.target 這兩個屬性值來指定jdk版本

  • maven.compiler.source

  • maven.compiler.target

maven.compiler.source
maven.compiler.target

在pom.xml中的位置

<project>
  <properties>
    <maven.compiler.source>21</maven.compiler.source>
    <maven.compiler.target>21</maven.compiler.target>
  </properties>
</project>

在settings.xml中的位置

<settings>
    <profiles>
        <profile>
            <activation>
                <activeByDefault>true</activeByDefault>
            </activation>
            <properties>
                <maven.compiler.source>21</maven.compiler.source>
                <maven.compiler.target>21</maven.compiler.target>  <!-- JRE System Liblary 的版本和這句相同  -->
            </properties>
        </profile>
    </profiles>
</settings>

在spring項目中, 用java.version來統(tǒng)一設(shè)置

maven的settings.xm和pom.xml也可以通過設(shè)定 maven-compiler-plugin 這個插件來指定jdk版本

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-compiler-plugin</artifactId>
    <version>3.9.6</version>
    <configuration>
        <source>21</source>
        <target>21</target>
    </configuration>
</plugin>

在pom.xml中的位置

<project>
  ...
  <build>
    ...
    <plugins>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-compiler-plugin</artifactId>
        <version>3.9.6</version>
        <configuration>
          <source>21</source>
          <target>21</target>
        </configuration>
      </plugin>
    </plugins>
    ...
  </build>
  ...
</project>

在settings.xml中的位置 , 好像用不了

<settings>
  ...
  <profiles>
    <profile>
      <id>profile-maven-compiler-plugin</id>
      <activation>
        <activeByDefault>true</activeByDefault>
      </activation>
      <build>
        <plugins>
          <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <version>3.9.6</version>
            <configuration>
              <source>17</source>
              <target>17</target>
            </configuration>
          </plugin>
        </plugins>
      </build>
    </profile>
  </profiles>
  ...
</settings>

Maven 在 settings.xml 中指定jdk版本

settings.xml 中的屬性寫在 setting??profiles??profile??properties中,位于第5層

方法一, 直接寫死, 例如指定jdk21

<settings>
    <profiles>
        <profile>
            <id>jdk-version-21</id>
            <!-- id和activation都可以用于激活該profile, 定義id可以在activeProfiles的activeProfile里設(shè)置該id從而激活該id代表的profile, id和activation可以只保留一個,也可兩個都使用.  -->
            <activation>
                <activeByDefault>true</activeByDefault> <!-- 該profile是否默認激活, 不激活的話, 下面的properties是否默認生效, 這里設(shè)為true就能激活該profile從而使屬性生效. 下方又用<activeProfile>jdk-version-21</activeProfile>再次確保該profile激活 -->
            </activation>
            <!--要使properties起作用, properties所屬的profile必須在激活狀態(tài)  -->
            <properties>
                <maven.compiler.source>21</maven.compiler.source>
                <maven.compiler.target>21</maven.compiler.target>  <!-- JRE System Liblary 的版本和這句相同  -->
            </properties>
        </profile>
    </profiles>
    <!--  activeProfiles里的activeProfile對應(yīng)profiles里的profile的id; 是激活profile的方式之一; 在activeProfiles中激活的profile可以不要activation標簽了-->
    <!--  activeProfiles與profiles同級是第二級, profile是第三級, settings → activeProfiles → activeProfile  ,  activeProfile可以有多個-->
    <activeProfiles>
        <!-- 要激活的profile的id , 在這里激活了的profile里的activation就無效了,可以去掉,當然也可以保留-->
        <activeProfile>jdk-version-21</activeProfile>  <!-- 要激活的profile的id . 這里和上面該id的profile中的 <activeByDefault>true</activeByDefault> 任一個都能激活該id代表的profile, 兩處設(shè)置確保啟用該profile-->
    </activeProfiles>
</settings>

去掉注釋

    <profiles>
        <profile>
            <id>jdk-version-21</id>
            <activation>
                <activeByDefault>true</activeByDefault> <!-- 該profile是否默認激活, 不激活的話, 下面的properties是否默認生效, 這里設(shè)為true就能激活該profile從而使屬性生效. 下方又用<activeProfile>jdk-version-21</activeProfile>再次確保該profile激活 -->
            </activation>
            <properties>
                <maven.compiler.source>21</maven.compiler.source>
                <maven.compiler.target>21</maven.compiler.target>  <!-- JRE System Liblary 的版本和這句相同  -->
            </properties>
        </profile>
    </profiles>
    <activeProfiles>
        <activeProfile>jdk-version-21</activeProfile>  <!-- 要激活的profile的id . 這里和上面該id的profile中的 <activeByDefault>true</activeByDefault> 任一個都能激活該id代表的profile, 兩處設(shè)置確保啟用該profile-->
    </activeProfiles>

只用 <activeByDefault>true</activeByDefault> 激活, 可以不要 <id>jdk-version-21</id>和 <activeProfile>jdk-version-21</activeProfile>

    <profiles>
        <profile>
            <activation>
                <activeByDefault>true</activeByDefault>
            </activation>
            <properties>
                <maven.compiler.source>21</maven.compiler.source>
                <maven.compiler.target>21</maven.compiler.target>  <!-- JRE System Liblary 的版本和這句相同  -->
            </properties>
        </profile>
    </profiles>

只用 <activeProfile>jdk-version-21</activeProfile> 激活 , 則可以不要

    <profiles>
        <profile>
            <id>jdk-version-21</id>
            <properties>
                <maven.compiler.source>21</maven.compiler.source>
                <maven.compiler.target>21</maven.compiler.target>  <!-- JRE System Liblary 的版本和這句相同  -->
            </properties>
        </profile>
    </profiles>
    <activeProfiles>
        <activeProfile>jdk-version-21</activeProfile>
    </activeProfiles>

引用屬性變量,只在一個地方修設(shè)值jdk版本

<settings>
    <profiles>
        <profile>
            <id>set-jdk-version</id>
            <!-- id和activation都可以用于激活該profile, 定義id可以在activeProfiles的activeProfile里設(shè)置該id從而激活該id代表的profile, id和activation可以只保留一個,也可兩個都使用.  -->
            <activation>
                <activeByDefault>true</activeByDefault> <!-- 該profile是否默認激活, 不激活的話, 下面的properties是否默認生效, 這里設(shè)為true就能激活該profile從而使屬性生效. 下方又用<activeProfile>jdk-version-21</activeProfile>再次確保該profile激活 -->
            </activation>
            <!--要使properties起作用, properties所屬的profile必須在激活狀態(tài)  -->
            <properties>
                <jdk-version>21</jdk-version> <!--自定義一個屬性用來設(shè)置版本,之后可以用${該屬性名引用},就不用多處修改了-->
                <maven.compiler.source>${jdk-version}</maven.compiler.source>
                <maven.compiler.target>${jdk-version}</maven.compiler.target>  <!-- JRE System Library 的版本和這句相同  -->
            </properties>
        </profile>
    </profiles>
    <!--  activeProfiles里的activeProfile對應(yīng)profiles里的profile的id; 是激活profile的方式之一; 在activeProfiles中激活的profile可以不要activation標簽了-->
    <!--  activeProfiles與profiles同級是第二級, profile是第三級, settings → activeProfiles → activeProfile  ,  activeProfile可以有多個-->
    <activeProfiles>
        <!-- 要激活的profile的id , 在這里激活了的profile里的activation就無效了,可以去掉,當然也可以保留-->
        <activeProfile>set-jdk-version</activeProfile>  <!-- 要激活的profile的id . 這里和上面該id的profile中的 <activeByDefault>true</activeByDefault> 任一個都能激活該id代表的profile, 兩處設(shè)置確保啟用該profile-->
    </activeProfiles>
</settings>

一處設(shè)置,雙重激活

    <profiles>
        <profile>
            <id>set-JdkVersion</id>
            <activation>
                <activeByDefault>true</activeByDefault> <!-- 該profile是否默認激活, 不激活的話, 下面的properties是否默認生效, 這里設(shè)為true就能激活該profile從而使屬性生效. 下方又用<activeProfile>JdkVersion-21</activeProfile>再次確保該profile激活 -->
            </activation>
            <properties>
                <JdkVersion>21</JdkVersion> <!--自定義一個屬性用來設(shè)置版本,之后可以用${該屬性名引用},就不用多處修改了-->
                <maven.compiler.source>${JdkVersion}</maven.compiler.source>
                <maven.compiler.target>${JdkVersion}</maven.compiler.target>  <!-- JRE System Library 的版本和這句相同  -->
            </properties>
        </profile>
    </profiles>
    <activeProfiles>
        <activeProfile>set-JdkVersion</activeProfile>  <!-- 要激活的profile的id . 這里和上面該id的profile中的 <activeByDefault>true</activeByDefault> 任一個都能激活該id代表的profile, 兩處設(shè)置確保啟用該profile-->
    </activeProfiles>

Maven 在 pom.xml 中指定jdk版本

在pom.xml中可以用設(shè)置屬性或者設(shè)置插件兩種方法來設(shè)置jdk版本

  • 用設(shè)置屬性的方式
<project>
  <properties>
    <maven.compiler.source>21</maven.compiler.source>
    <maven.compiler.target>21</maven.compiler.target>
  </properties>
</project>
    <maven.compiler.source>21</maven.compiler.source>
    <maven.compiler.target>21</maven.compiler.target>
  • 用設(shè)置插件的方式 , 設(shè)置插件的方式優(yōu)先級高于設(shè)置屬性
<project>
  ...
  <build>
    ...
    <plugins>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-compiler-plugin</artifactId>
        <!-- <version>3.9.6</version> --> <!-- 可以不要version -->
        <configuration>
          <source>21</source>
          <target>21</target>
        </configuration>
      </plugin>
    </plugins>
    ...
  </build>
  ...
</project>
  • 用設(shè)置插件的方式 , 設(shè)置插件的方式優(yōu)先級高于設(shè)置屬性
    <plugins>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-compiler-plugin</artifactId>
        <!-- <version>3.9.6</version> --> <!-- 可以不要version -->
        <configuration>
          <source>21</source>
          <target>21</target>
        </configuration>
      </plugin>
    </plugins>

兩種方法都用上, , 插件的優(yōu)先級高于屬性

  <properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <JdkVersionOfThisPom>17</JdkVersionOfThisPom>
    <java.version>${JdkVersionOfThisPom}</java.version>
    <maven.compiler.source>${JdkVersionOfThisPom}</maven.compiler.source>
    <maven.compiler.target>${JdkVersionOfThisPom}</maven.compiler.target>
    <maven.compiler.compilerVersion>${JdkVersionOfThisPom}</maven.compiler.compilerVersion>
  </properties>
  <build>
    <plugins>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-compiler-plugin</artifactId>
<!--        <version>3.9.6</version>-->
        <configuration>
          <source>${JdkVersionOfThisPom}</source>
          <target>${JdkVersionOfThisPom}</target>
          <compilerVersion>${JdkVersionOfThisPom}</compilerVersion>
        </configuration>
      </plugin>
    </plugins>
  </build>

總結(jié) 

到此這篇關(guān)于maven在settings.xm和pom.xml中指定jdk版本編譯的文章就介紹到這了,更多相關(guān)maven指定jdk版本編譯內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

相關(guān)文章

  • 詳解Spring系列之@ComponentScan自動掃描組件

    詳解Spring系列之@ComponentScan自動掃描組件

    這篇文章主要介紹了Spring @ComponentScan自動掃描組件使用,本文通過實例代碼給大家介紹的非常詳細,對大家的學(xué)習或工作具有一定的參考借鑒價值,需要的朋友可以參考下
    2022-06-06
  • Spring依賴注入的三種方式詳解

    Spring依賴注入的三種方式詳解

    這篇文章主要給大家介紹了三種Spring依賴注入的方式,?settter方法注入,構(gòu)造器注入以及變量(filed)?注入這三種方式,文章通過代碼示例給大家介紹的非常詳細,需要的朋友可以參考下
    2023-11-11
  • 淺談SpringBoot內(nèi)嵌Tomcat的實現(xiàn)原理解析

    淺談SpringBoot內(nèi)嵌Tomcat的實現(xiàn)原理解析

    這篇文章主要介紹了淺談SpringBoot內(nèi)嵌Tomcat的實現(xiàn)原理解析,文中通過示例代碼介紹的非常詳細,對大家的學(xué)習或者工作具有一定的參考學(xué)習價值,需要的朋友們下面隨著小編來一起學(xué)習學(xué)習吧
    2020-12-12
  • java中ArrayList與LinkedList對比詳情

    java中ArrayList與LinkedList對比詳情

    這篇文章主要通過實例對Java中ArrayList與LinkedList進行了對比,需要的朋友可以參考下
    2017-04-04
  • Java SpringMVC 集成靜態(tài)資源的方式你了解嗎

    Java SpringMVC 集成靜態(tài)資源的方式你了解嗎

    本篇文章主要介紹了SpringMVC集成靜態(tài)資源的方法,小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧
    2021-10-10
  • springBoot+mybaties后端多層架構(gòu)的實現(xiàn)示例

    springBoot+mybaties后端多層架構(gòu)的實現(xiàn)示例

    本文主要介紹了springBoot+mybaties后端多層架構(gòu)的實現(xiàn)示例,文中通過示例代碼介紹的非常詳細,對大家的學(xué)習或者工作具有一定的參考學(xué)習價值,需要的朋友們下面隨著小編來一起學(xué)習學(xué)習吧
    2022-07-07
  • Springboot 2.6集成redis maven報錯的坑記錄

    Springboot 2.6集成redis maven報錯的坑記錄

    這篇文章主要介紹了Springboot 2.6集成redis maven報錯的坑記錄,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教
    2023-04-04
  • Java?協(xié)程?Quasar詳解

    Java?協(xié)程?Quasar詳解

    這篇文章主要介紹了Java?協(xié)程?Quasar詳解,文章圍繞主題展開詳細的內(nèi)容介紹,具有一定的參考價值,需要的小伙伴可以參考一下
    2022-07-07
  • Java使用EasyExcel實現(xiàn)高效的Excel讀寫操作

    Java使用EasyExcel實現(xiàn)高效的Excel讀寫操作

    在日常開發(fā)中,Excel 文件的讀寫操作是一個常見的需求,EasyExcel 是阿里巴巴開源的一個高性能、易用的 Excel 讀寫庫,可以大幅提高處理 Excel 文件的效率,本篇博客將從 EasyExcel 的基本概念、優(yōu)勢、安裝、讀寫操作以及高級用法展開,需要的朋友可以參考下
    2024-12-12
  • Java常用線程池原理及使用方法解析

    Java常用線程池原理及使用方法解析

    這篇文章主要介紹了Java常用線程池原理及使用方法解析,文中通過示例代碼介紹的非常詳細,對大家的學(xué)習或者工作具有一定的參考學(xué)習價值,需要的朋友可以參考下
    2020-07-07

最新評論

昌都县| 界首市| 海城市| 平潭县| 平原县| 鄢陵县| 常州市| 金沙县| 依安县| 金川县| 柏乡县| 大连市| 拜城县| 东光县| 东莞市| 甘泉县| 蓝田县| 临潭县| 和政县| 永修县| 海阳市| 沈丘县| 姜堰市| 江源县| 吴桥县| 江口县| 寿阳县| 灵石县| 麻城市| 定南县| 施甸县| 梨树县| 长春市| 河东区| 南充市| 星子县| 柳江县| 乌兰察布市| 贵阳市| 牙克石市| 康平县|