色婷婷综合在线,在线日韩欧美一区二区三区,欧美日韩中文字幕在线,一区国产视频,极品嫩模,h美女漫画网站,亚洲wuma

您的位置:首頁>熱點推薦 >

Maven中settings.xml有什么用?以及其中的各種標簽的作用

2023-03-02 09:00:41    來源:騰訊云

settings.xml有什么用?

如果在Eclipse中使用過Maven插件,想必會有這個經驗:配置settings.xml文件的路徑。

settings.xml文件是干什么的,為什么要配置它呢?從settings.xml的文件名就可以看出,它是用來設置maven參數的配置文件。并且,settings.xml是maven的全局配置文件。而pom.xml文件是所在項目的局部配置。Settings.xml中包含類似本地倉儲位置、修改遠程倉儲服務器(如阿里云的遠程倉庫)、認證信息等配置(比如對于某個遠程的倉庫需要用戶名和密碼的話也需要在這個setting.xml中進行配置)。


【資料圖】

在setting.xml中配置阿里云的遠程倉庫:

                           alimaven            *            aliyun maven            http://maven.aliyun.com/nexus/content/repositories/central/                                    repo1            central            Human Readable Name for this Mirror.            http://repo1.maven.org/maven2/                                    repo2            central            Human Readable Name for this Mirror.            http://repo2.maven.org/maven2/            

settings.xml文件位置

settings.xml文件一般存在于兩個位置:全局配置: ${M2_HOME}/conf/settings.xml用戶配置: 用戶配置優(yōu)先于全局配置。user.home/.m2/settings.xmlnote:用戶配置優(yōu)先于全局配置。{user.home} 和和所有其他系統(tǒng)屬性只能在3.0+版本上使用。請注意windows和Linux使用變量的區(qū)別。

配置優(yōu)先級

eclipse對于Maven工程中需要注意的是:局部配置優(yōu)先于全局配置。配置優(yōu)先級從高到低:pom.xml> user settings > global settings如果這些文件同時存在,在應用配置時,會合并它們的內容,如果有重復的配置,優(yōu)先級高的配置會覆蓋優(yōu)先級低的。

settings.xml元素詳解

頂級元素概覽

下面列舉了settings.xml中的頂級元素

                    

LocalRepository

作用:該值表示構建系統(tǒng)本地倉庫的路徑其默認值:~/.m2/repository。

${user.home}/.m2/repository

InteractiveMode

作用:表示maven是否需要和用戶交互以獲得輸入。如果maven需要和用戶交互以獲得輸入,則設置成true,反之則應為false。默認為true。

true

UsePluginRegistry

作用:maven是否需要使用plugin-registry.xml文件來管理插件版本。如果需要讓maven使用文件~/.m2/plugin-registry.xml來管理插件版本,則設為true。默認為false。

false

Offline

作用:表示maven是否需要在離線模式下運行。如果構建系統(tǒng)需要在離線模式下運行,則為true,默認為false。當由于網絡設置原因或者安全因素,構建服務器不能連接遠程倉庫的時候,該配置就十分有用。

false

PluginGroups

作用:當插件的組織id(groupId)沒有顯式提供時,供搜尋插件組織Id(groupId)的列表。該元素包含一個pluginGroup元素列表,每個子元素包含了一個組織Id(groupId)。當我們使用某個插件,并且沒有在命令行為其提供組織Id(groupId)的時候,Maven就會使用該列表。默認情況下該列表包含了org.apache.maven.pluginsorg.codehaus.mojo。

  ...          org.codehaus.mojo    ...

Servers

作用:一般,倉庫的下載和部署是在pom.xml文件中的repositoriesdistributionManagement元素中定義的。然而,一般類似用戶名、密碼(有些倉庫訪問是需要安全認證的)等信息不應該在pom.xml文件中配置,這些信息可以配置在settings.xml中。

  ...                        server001            my_login            my_password            ${usr.home}/.ssh/id_dsa            some_passphrase            664            775        ...

Mirrors

作用:為倉庫列表配置的下載鏡像列表。

  ...                      planetmirror.com            PlanetMirror Australia            http://downloads.planetmirror.com/pub/maven2            central        ...

Proxies

作用:用來配置不同的代理。

  ...                      myproxy            true            http            proxy.somewhere.com            8080            proxyuser            somepassword            *.google.com|ibiblio.org        ...

Profiles

作用:根據環(huán)境參數來調整構建配置的列表。settings.xml中的profile元素是pom.xmlprofile元素的裁剪版本。它包含了idactivation、repositoriespluginRepositoriesproperties元素。這里的profile元素只包含這五個子元素是因為這里只關心構建系統(tǒng)這個整體(這正是settings.xml文件的角色定位),而非單獨的項目對象模型設置。如果一個settings.xml中的profile被激活,它的值會覆蓋任何其它定義在pom.xml中帶有相同id的profile。

  ...                  test                                                        ...

Activation

作用:自動觸發(fā)profile的條件邏輯。如pom.xml中的profile一樣,profile的作用在于它能夠在某些特定的環(huán)境中自動使用某些特定的值;這些環(huán)境通過activation元素指定。activation元素并不是激活profile的唯一方式。settings.xml文件中的activeProfile元素可以包含profileidprofile也可以通過在命令行,使用-P標記和逗號分隔的列表來顯式的激活(如,-P test)。

    false    1.5            Windows XP        Windows        x86        5.1.2600              mavenVersion        2.0.3              ${basedir}/file2.properties        ${basedir}/file1.properties  

注:在maven工程的pom.xml所在目錄下執(zhí)行mvn help:active-profiles命令可以查看中央倉儲的profile是否在工程中生效。

properties

作用:對應profile的擴展屬性列表。maven屬性和ant中的屬性一樣,可以用來存放一些值。這些值可以在pom.xml中的任何地方使用標記${X}來使用,這里X是指屬性的名稱。屬性有五種不同的形式,并且都能在settings.xml文件中訪問。

  ${user.home}/our-project

注:如果在setting.xml中的profile被激活,則可以在pom.xml中使用${user.install}。

Repositories

作用:遠程倉庫列表,它是maven用來填充構建系統(tǒng)本地倉庫所使用的一組遠程倉庫。

            codehausSnapshots        Codehaus Snapshots                    false            always            warn                                          http://snapshots.maven.codehaus.org/maven2        default  

pluginRepositories

作用:發(fā)現插件的遠程倉庫列表。和repository類似,只是repository是管理jar包依賴的倉庫,pluginRepositories則是管理插件的倉庫。maven插件是一種特殊類型的構件。由于這個原因,插件倉庫獨立于其它倉庫。pluginRepositories元素的結構和repositories元素的結構類似。每個pluginRepository元素指定一個Maven可以用來尋找新插件的遠程地址。

                                                                          

ActiveProfiles

作用:手動激活profiles的列表,按照profile被應用的順序定義activeProfile。該元素包含了一組activeProfile元素,每個activeProfile都含有一個profile id。任何在activeProfile中定義的profile id,不論環(huán)境設置如何,其對應的 profile都會被激活。如果沒有匹配的profile,則什么都不會發(fā)生。例如,env-test是一個activeProfile,則在pom.xml(或者profile.xml)中對應id的profile會被激活。如果運行過程中找不到這樣一個profile,Maven則會像往常一樣運行。

  ...          env-test    ...

關鍵詞: GitHub Maven

相關閱讀

许昌市| 黔西| 禹州市| 阳春市| 偃师市| 乐都县| 周口市| 沙坪坝区| 张家港市| 泰安市| 沙河市| 文山县| 保德县| 平顶山市| 吴旗县| 柳河县| 收藏| 封丘县| 乌鲁木齐县| 西藏| 河北区| 崇左市| 海淀区| 青田县| 黄陵县| 连州市| 阳东县| 重庆市| 理塘县| 鹿邑县| 南开区| 延长县| 顺义区| 咸阳市| 贵溪市| 富蕴县| 葵青区| 太仆寺旗| 汨罗市| 宁乡县| 桐城市|