欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

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

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

maven的settings.xm和pom.xml都可以通過 maven.compiler.source , maven.compiler.target 這兩個(gè)屬性值來(lái)指定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項(xiàng)目中, 用java.version來(lái)統(tǒng)一設(shè)置

maven的settings.xm和pom.xml也可以通過設(shè)定 maven-compiler-plugin 這個(gè)插件來(lái)指定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可以只保留一個(gè),也可兩個(gè)都使用.  -->
            <activation>
                <activeByDefault>true</activeByDefault> <!-- 該profile是否默認(rèn)激活, 不激活的話, 下面的properties是否默認(rèn)生效, 這里設(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對(duì)應(yīng)profiles里的profile的id; 是激活profile的方式之一; 在activeProfiles中激活的profile可以不要activation標(biāo)簽了-->
    <!--  activeProfiles與profiles同級(jí)是第二級(jí), profile是第三級(jí), settings → activeProfiles → activeProfile  ,  activeProfile可以有多個(gè)-->
    <activeProfiles>
        <!-- 要激活的profile的id , 在這里激活了的profile里的activation就無(wú)效了,可以去掉,當(dāng)然也可以保留-->
        <activeProfile>jdk-version-21</activeProfile>  <!-- 要激活的profile的id . 這里和上面該id的profile中的 <activeByDefault>true</activeByDefault> 任一個(gè)都能激活該id代表的profile, 兩處設(shè)置確保啟用該profile-->
    </activeProfiles>
</settings>

去掉注釋

    <profiles>
        <profile>
            <id>jdk-version-21</id>
            <activation>
                <activeByDefault>true</activeByDefault> <!-- 該profile是否默認(rèn)激活, 不激活的話, 下面的properties是否默認(rèn)生效, 這里設(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> 任一個(gè)都能激活該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>

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

<settings>
    <profiles>
        <profile>
            <id>set-jdk-version</id>
            <!-- id和activation都可以用于激活該profile, 定義id可以在activeProfiles的activeProfile里設(shè)置該id從而激活該id代表的profile, id和activation可以只保留一個(gè),也可兩個(gè)都使用.  -->
            <activation>
                <activeByDefault>true</activeByDefault> <!-- 該profile是否默認(rèn)激活, 不激活的話, 下面的properties是否默認(rèn)生效, 這里設(shè)為true就能激活該profile從而使屬性生效. 下方又用<activeProfile>jdk-version-21</activeProfile>再次確保該profile激活 -->
            </activation>
            <!--要使properties起作用, properties所屬的profile必須在激活狀態(tài)  -->
            <properties>
                <jdk-version>21</jdk-version> <!--自定義一個(gè)屬性用來(lái)設(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對(duì)應(yīng)profiles里的profile的id; 是激活profile的方式之一; 在activeProfiles中激活的profile可以不要activation標(biāo)簽了-->
    <!--  activeProfiles與profiles同級(jí)是第二級(jí), profile是第三級(jí), settings → activeProfiles → activeProfile  ,  activeProfile可以有多個(gè)-->
    <activeProfiles>
        <!-- 要激活的profile的id , 在這里激活了的profile里的activation就無(wú)效了,可以去掉,當(dāng)然也可以保留-->
        <activeProfile>set-jdk-version</activeProfile>  <!-- 要激活的profile的id . 這里和上面該id的profile中的 <activeByDefault>true</activeByDefault> 任一個(gè)都能激活該id代表的profile, 兩處設(shè)置確保啟用該profile-->
    </activeProfiles>
</settings>

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

    <profiles>
        <profile>
            <id>set-JdkVersion</id>
            <activation>
                <activeByDefault>true</activeByDefault> <!-- 該profile是否默認(rèn)激活, 不激活的話, 下面的properties是否默認(rèn)生效, 這里設(shè)為true就能激活該profile從而使屬性生效. 下方又用<activeProfile>JdkVersion-21</activeProfile>再次確保該profile激活 -->
            </activation>
            <properties>
                <JdkVersion>21</JdkVersion> <!--自定義一個(gè)屬性用來(lái)設(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> 任一個(gè)都能激活該id代表的profile, 兩處設(shè)置確保啟用該profile-->
    </activeProfiles>

Maven 在 pom.xml 中指定jdk版本

在pom.xml中可以用設(shè)置屬性或者設(shè)置插件兩種方法來(lái)設(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)先級(jí)高于設(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)先級(jí)高于設(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)先級(jí)高于屬性

  <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)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

相關(guān)文章

  • Java多線程循環(huán)柵欄CyclicBarrier正確使用方法

    Java多線程循環(huán)柵欄CyclicBarrier正確使用方法

    這篇文章主要介紹了Java多線程循環(huán)柵欄CyclicBarrier正確使用方法詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪
    2023-09-09
  • Java常見面試題之多線程和高并發(fā)詳解

    Java常見面試題之多線程和高并發(fā)詳解

    這篇文章主要給大家介紹了關(guān)于Java面試題之多線程和高并發(fā)的相關(guān)資料,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家學(xué)習(xí)或者使用java具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面來(lái)一起學(xué)習(xí)學(xué)習(xí)吧
    2019-04-04
  • Java的SpringMVC中控制器返回XML數(shù)據(jù)問題

    Java的SpringMVC中控制器返回XML數(shù)據(jù)問題

    這篇文章主要介紹了Java的SpringMVC中控制器返回XML數(shù)據(jù)問題,控制器是處理HTTP請(qǐng)求的組件,它們接收來(lái)自客戶端的請(qǐng)求,并將其轉(zhuǎn)換為適當(dāng)?shù)捻憫?yīng),這些響應(yīng)可以是動(dòng)態(tài)生成的?HTML?頁(yè)面,也可以是JSON或XML格式的數(shù)據(jù),需要的朋友可以參考下
    2023-07-07
  • Java實(shí)體類之間的相互轉(zhuǎn)換方式

    Java實(shí)體類之間的相互轉(zhuǎn)換方式

    這篇文章主要介紹了Java實(shí)體類之間的相互轉(zhuǎn)換方式,具有很好的參考價(jià)值,希望對(duì)大家有所幫助,如有錯(cuò)誤或未考慮完全的地方,望不吝賜教
    2023-08-08
  • SpringBoot中Token登錄授權(quán)、續(xù)期和主動(dòng)終止的方案流程分析

    SpringBoot中Token登錄授權(quán)、續(xù)期和主動(dòng)終止的方案流程分析

    SpringBoot項(xiàng)目中,基于Token的登錄授權(quán)方案主要有兩種:利用Session/Cookie和JWT,Cookie/Session方案有狀態(tài),不適合分布式架構(gòu),而JWT雖無(wú)狀態(tài),但存在過期時(shí)間不可強(qiáng)制失效、一次性等缺點(diǎn),本文介紹SpringBoot中Token登錄授權(quán)、續(xù)期和主動(dòng)終止的方案,感興趣的朋友一起看看吧
    2024-09-09
  • Mybatis-plus數(shù)據(jù)權(quán)限D(zhuǎn)ataPermissionInterceptor實(shí)現(xiàn)

    Mybatis-plus數(shù)據(jù)權(quán)限D(zhuǎn)ataPermissionInterceptor實(shí)現(xiàn)

    本文主要介紹了Mybatis-plus數(shù)據(jù)權(quán)限D(zhuǎn)ataPermissionInterceptor實(shí)現(xiàn),文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧
    2022-07-07
  • Javaweb實(shí)現(xiàn)完整個(gè)人博客系統(tǒng)流程

    Javaweb實(shí)現(xiàn)完整個(gè)人博客系統(tǒng)流程

    這篇文章主要介紹了怎樣用Java來(lái)實(shí)現(xiàn)一個(gè)完整的個(gè)人博客系統(tǒng),我們通過實(shí)操上手的方式可以高效的鞏固所學(xué)的基礎(chǔ)知識(shí),感興趣的朋友一起來(lái)看看吧
    2022-03-03
  • 關(guān)于SpringBoot獲取IOC容器中注入的Bean(推薦)

    關(guān)于SpringBoot獲取IOC容器中注入的Bean(推薦)

    本文通過實(shí)例代碼給大家詳解了springboot獲取ioc容器中注入的bean問題,非常不錯(cuò),具有一定的參考借鑒價(jià)值,需要的朋友參考下吧
    2018-05-05
  • Java Junit單元測(cè)試實(shí)例詳解

    Java Junit單元測(cè)試實(shí)例詳解

    在本篇文章里小編給大家分享的是關(guān)于Java Junit單元測(cè)試的相關(guān)知識(shí)點(diǎn)內(nèi)容,有興趣的朋友們學(xué)習(xí)下。
    2019-11-11
  • MyBatis-Plus allEq()的用法詳解

    MyBatis-Plus allEq()的用法詳解

    這篇文章主要介紹了MyBatis-Plus allEq()的用法詳解,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧
    2020-12-12

最新評(píng)論