亚洲乱码中文字幕综合,中国熟女仑乱hd,亚洲精品乱拍国产一区二区三区,一本大道卡一卡二卡三乱码全集资源,又粗又黄又硬又爽的免费视频

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)文章

  • mybatis.type-aliases-package的作用及用法說明

    mybatis.type-aliases-package的作用及用法說明

    這篇文章主要介紹了mybatis.type-aliases-package的作用及用法說明,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教
    2022-01-01
  • Nacos客戶端配置中心緩存動態(tài)更新實現(xiàn)源碼

    Nacos客戶端配置中心緩存動態(tài)更新實現(xiàn)源碼

    這篇文章主要為大家介紹了Nacos客戶端配置中心緩存動態(tài)更新實現(xiàn)源碼,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進步早日升職加薪
    2022-03-03
  • Java notify和notifyAll的區(qū)別和相同

    Java notify和notifyAll的區(qū)別和相同

    本文主要介紹Java notify和notifyAll的知識,這里整理詳細的資料來說明notify 和NotifAll的區(qū)別,有需要的小伙伴可以參考下
    2016-09-09
  • 淺談為什么同一個java文件只能有一個public類

    淺談為什么同一個java文件只能有一個public類

    這篇文章主要介紹了淺談為什么同一個java文件只能有一個public類,文中通過示例代碼介紹的非常詳細,對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2019-11-11
  • MyBatis-Plus中實現(xiàn)自定義復(fù)雜排序邏輯的詳細步驟

    MyBatis-Plus中實現(xiàn)自定義復(fù)雜排序邏輯的詳細步驟

    這篇文章主要介紹了MyBatis-Plus中實現(xiàn)自定義復(fù)雜排序邏輯,通過使用MyBatis-Plus的QueryWrapper和SQL原始片段,我們可以靈活地實現(xiàn)復(fù)雜的數(shù)據(jù)排序邏輯,這種方法尤其適用于需要對數(shù)據(jù)進行特定規(guī)則排序的場景,需要的朋友可以參考下
    2024-07-07
  • 二代身份證驗證示例

    二代身份證驗證示例

    這篇文章主要介紹了二代身份證驗證示例,需要的朋友可以參考下
    2014-02-02
  • 詳解如何在Java8中創(chuàng)建和使用線程池

    詳解如何在Java8中創(chuàng)建和使用線程池

    在 Java 8 中,線程池(Thread Pool)是一種管理線程資源的機制,能夠有效地控制并發(fā)執(zhí)行的線程數(shù)量,減少線程創(chuàng)建和銷毀的開銷,提高系統(tǒng)的性能,本篇文章將詳細介紹如何在 Java 8 中創(chuàng)建和使用線程池,需要的朋友可以參考下
    2024-06-06
  • 教你用Java Swing實現(xiàn)自助取款機系統(tǒng)

    教你用Java Swing實現(xiàn)自助取款機系統(tǒng)

    今天給大家?guī)淼氖顷P(guān)于JAVA的相關(guān)知識,文章圍繞著如何用Java Swing實現(xiàn)自助取款機系統(tǒng)展開,文中有非常詳細的介紹及代碼示例,需要的朋友可以參考下
    2021-06-06
  • Jpa數(shù)據(jù)操作以及@Query和@Modifying注解使用方式

    Jpa數(shù)據(jù)操作以及@Query和@Modifying注解使用方式

    這篇文章主要介紹了Jpa數(shù)據(jù)操作以及@Query和@Modifying注解使用方式,具有很好的參考價值,希望對大家有所幫助,如有錯誤或未考慮完全的地方,望不吝賜教
    2024-07-07
  • JsonObject的屬性與值的判空(Null值)處理方式

    JsonObject的屬性與值的判空(Null值)處理方式

    這篇文章主要介紹了JsonObject的屬性與值的判空(Null值)處理方式,具有很好的參考價值,希望對大家有所幫助,如有錯誤或未考慮完全的地方,望不吝賜教
    2023-12-12

最新評論