1. 程式人生 > >Maven專案setting.xml配置檔案詳解

Maven專案setting.xml配置檔案詳解

Maven專案的setting.xml檔案,主要分為兩個:
使用者的安裝: ${user.home}/.m2/settings.xml 當前使用者範圍的配置檔案;
Maven安裝maven.conf/settings.xmlsettings.xmlMaven {user.home} /.m2目錄是最簡單的方法。Maven的預設settings.xml是一個包含註釋和示例的模板,可以快速調整它以符合需求。

注:當然意思不是說只能有兩個,只是配置範圍分為兩個,但是可以複製很多份,相對應到eclipse或者idea中的workspace可以指向不同的配置檔案,配置不同的倉庫或者使用者,可以根據實際使用需要區分開來。

setting.xml檔案引數含義:

  1. localRepository:自定義本地庫路徑,預設在 ${user.home}/.m2中;

  2. interactiveMode: 互動模式,Maven是否應該嘗試與使用者輸入互動,預設是true,如果不是false。

  3. offline:是否每次編譯都去查詢遠端中心庫, 如果此構建系統應以離線模式執行,則為true,預設為false。由於網路設定或安全原因,此元素對於構建無法連線到遠端儲存庫的伺服器非常有用。

  4. pluginGroups:外掛組,例如org.mortbay.jetty;

<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0"
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0
                      https://maven.apache.org/xsd/settings-1.0.0.xsd">
  ...
  <pluginGroups>
    <pluginGroup>org.mortbay.jetty</pluginGroup>
  </pluginGroups>
  ...
</settings>

例如,給定上述設定Maven命令可以執行:

mvn jetty:run
  1. servers:伺服器;
<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0"
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0
                      https://maven.apache.org/xsd/settings-1.0.0.xsd">
  ...
  <servers>
    <server>
      <id>server001</id>
      <username>my_login</username>
      <password>my_password</password>
      <privateKey>${user.home}/.ssh/id_dsa</privateKey>
      <passphrase>some_passphrase</passphrase>
      <filePermissions>664</filePermissions>
      <directoryPermissions>775</directoryPermissions>
      <configuration></configuration>
    </server>
  </servers>
  ...
</settings>

id:與Maven試圖連線的資源庫/映象的id元素相匹配的伺服器的標識(不是使用者登入的標識)。
username, password:表示向該伺服器進行身份驗證所需的登入名和密碼。
privateKey,passphrase:和前面的兩個元素一樣,如果需要的話,這一對指定一個私鑰的路徑(預設是${user.home}/.ssh/id_dsa)和密碼。該密碼和密碼的元素可能在將來被外部化,但現在他們必須設定在純文字的settings.xml檔案。
filePermissions,directoryPermissions:在部署中建立儲存庫檔案或目錄時,這些是要使用的許可權。每個的合法值是一個三位數的數字,相當於* nix檔案的許可權,如:664或775。
注意:如果使用私鑰登入到伺服器,請確保省略元素。否則,該鍵將被忽略。
Maven 2.1.0以上版本支援伺服器密碼加密
有這方面的興趣或需求可以參考https://maven.apache.org/guides/mini/guide-encryption.html

  1. mirrors:映象庫,可以指定內部中心庫;
<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0"
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0
                      https://maven.apache.org/xsd/settings-1.0.0.xsd">
  ...
  <mirrors>
    <mirror>
      <id>planetmirror.com</id>
      <name>PlanetMirror Australia</name>
      <url>http://downloads.planetmirror.com/pub/maven2</url>
      <mirrorOf>central</mirrorOf>
    </mirror>
  </mirrors>
  ...
</settings>

id,name:映象的唯一識別符號和使用者的名字。該id用於區分映象元素,並在連線映象時從部分選擇相應的憑據。
url:映象的基本URL。構建系統將使用此URL來連線到儲存庫,而不是原始儲存庫URL。
mirrorOf:這是一個映象的儲存庫的ID。
例如,要指向Maven 中央儲存庫(https://repo.maven.apache.org/maven2/)的映象,設定為central。也可以設定為repo1,repo2或*,!inhouse。

  1. proxies:個性配置,需要在中啟用;
<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0"
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0
                      https://maven.apache.org/xsd/settings-1.0.0.xsd">
  ...
  <proxies>
    <proxy>
      <id>myproxy</id>
      <active>true</active>
      <protocol>http</protocol>
      <host>proxy.somewhere.com</host>
      <port>8080</port>
      <username>proxyuser</username>
      <password>somepassword</password>
      <nonProxyHosts>*.google.com|ibiblio.org</nonProxyHosts>
    </proxy>
  </proxies>
  ...
</settings>

id:此代理的唯一識別符號,用於區分代理元素。
active:如果此代理處於活動狀態,則為true。對於宣告一組代理是必需的,但是一次只能啟用一個代理。
protocol, host, port: :protocol://host:port。
username, password:表示對此代理伺服器進行身份驗證所需的登入名和密碼。
nonProxyHosts:這是不應代理的主機列表。

  1. activeProfiles:表示啟用的profile,載入所需的環境設定。
<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0"
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0
                      https://maven.apache.org/xsd/settings-1.0.0.xsd">
  ...
  <profiles>
    <profile>
      <id>test</id>
      <activation>
        <activeByDefault>false</activeByDefault>
        <jdk>1.5</jdk>
        <os>
          <name>Windows XP</name>
          <family>Windows</family>
          <arch>x86</arch>
          <version>5.1.2600</version>
        </os>
        <property>
          <name>mavenVersion</name>
          <value>2.0.3</value>
        </property>
        <file>
          <exists>${basedir}/file2.properties</exists>
          <missing>${basedir}/file1.properties</missing>
        </file>
      </activation>
      ...
    </profile>
  </profiles>
  ...
</settings>

相關推薦

Maven專案setting.xml配置檔案

Maven專案的setting.xml檔案,主要分為兩個: 使用者的安裝: ${user.home}/.m2/settings.xml 當前使用者範圍的配置檔案; Maven安裝: maven.conf/settings.xml全局範圍配置文件

Mavensetting.xml配置檔案

setting.xml配置檔案 maven的配置檔案settings.xml存在於兩個地方: 1.安裝的地方:${M2_HOME}/conf/settings.xml 2.使用者的目錄:${user.home}/.m2/settings.xml 前者又被叫做全域性配置,對作

maven安裝和eclipse整合以及Mavensetting.xml配置檔案

由於maven需要JDK的支援,所以在安裝maven之前請確保電腦上已經安裝了JDK,且配置好了環境變數,具體的JDK的安裝及配置可自行百度。下面進入安裝 一、maven安裝 前面已經下載了相應版本的maven,且已經配置好JDK的環境;     1

Maven使用者手冊】Mavensetting.xml配置檔案

setting.xml配置檔案 maven的配置檔案settings.xml存在於兩個地方: 1.安裝的地方:${M2_HOME}/conf/settings.xml 2.使用者的目錄:${user.home}/.m2/settings.xml 前者又被叫做全域性配置

Maven之pom.xmlsetting.xml配置檔案

一.pom.xml詳解     1.概述     pom中節點如下分佈 <project xmlns="http://maven.apache.org/

Maven的pom.xml配置檔案

轉自: Maven的pom.xml配置檔案詳解  <!--父專案的座標。如果專案中沒有規定某個元素的值,那麼父專案中的對應值即為專案的預設值。 座標包括group ID,artifact ID和 version。-->  &

maven的settings.xml配置檔案

一、Settings.xml基本資訊 Settings.xml是maven全域性引數的配置檔案,其中包含本地倉儲位置、遠端倉儲伺服器、認證資訊等等。 settings.xml檔案一般存在於兩個位置: 全域性配置(global settings): maven安裝目錄/conf/settings

Maven使用者手冊】Maven之pom.xml配置檔案

歡迎關注公眾號: ----------------------------------------------正文---------------------------------------------------- setting.xml主要用於配置m

Maven之(七)pom.xml配置檔案

setting.xml主要用於配置maven的執行環境等一系列通用的屬性,是全域性級別的配置檔案;而pom.xml主要描述了專案的maven座標,依賴關係,開發者需要遵循的規則,缺陷管理系統,組織和licenses,以及其他所有的專案相關因素,是專案級別的配置檔案。

Maven中的pom.xml配置檔案

<projectxmlns="http://maven.apache.org/POM/4.0.0"xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"     xsi:schemaLocation=

【MyBatis Generator】程式碼自動生成工具 generatorConfig.xml配置檔案

MyBatis Generator官網地址:http://www.mybatis.org/generator/index.html MyBaris Generator中文地址:http://mbg.cndocs.ml/ 在MBG中,最主要也最重要的,就是generatorConfig.xml

轉:ssm spring+springmvc+mybatis中的xml配置檔案

這幾天一直在整合SSM框架,雖然網上有很多已經整合好的,但是對於裡面的配置檔案並沒有進行過多的說明,很多人知其然不知其所以然,經過幾天的搜尋和整理,今天總算對其中的XML配置檔案有了一定的瞭解,所以拿出來一起分享一下,希望有不足的地方大家批評指正~~~ 首先   這篇文章暫時只對框架中所要用到的配

struts2中struts.xml配置檔案

<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE struts PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 2.3//EN" "http://st

Tomcat學習筆記【3】--- Server.xml配置檔案

本文主要講如何配置Tomcat伺服器。 首先展示一個BS結構圖: 1 server 一個server就表示一個Tomcat例項。 1)port 指定一個埠,這個埠負責監聽關閉tomcat的請求; 2)shutdown 指定向埠傳送的命令字串。 2 service 一個service就是處理請求的服務,裡邊包含

Android之androidmainfest.xml配置檔案

寫配置檔案的時候我們會不知道把那些配置項放在哪裡,請看: 配置檔案樣例: <?xml version="1.0" encoding="utf-8"?> <manifest> <!-- 基本配置 --> <uses-permission

KVM 虛擬機器 XML 配置檔案

我們使用 KVM 建立虛擬機器後,會在 /etc/libvirt/qemu/ 路徑下生成該虛擬機器的 xml 配置檔案,很多時候,我們會以此 xml 配置為模板,進行修改後來建立新的虛擬機器,這樣,就需要我們瞭解該配置檔案中各個欄位的意思,下面,就對該檔案做一說明: <!-- WARNING:&n

SSH框架之Struts的struts.xml配置檔案

struts.xml配置檔案詳解 方式一:只使用一個struts.xml配置檔案 <?xml version="1.0" encoding="UTF-8" ?> <!DOCTYPE struts PUBLIC "-/

轉:AndroidManifest.xml配置檔案

AndroidManifest.xml配置檔案對於Android應用開發來說是非常重要的基礎知識,本文旨在總結該配置檔案中重點的用法,以便日後查閱。下面是一個標準的AndroidManifest.xml檔案樣例。 <?xml version="1.0" encoding="utf-8"?> &

AndroidManifest.xml配置檔案-…

AndroidManifest.xml配置檔案對於Android應用開發來說是非常重要的基礎知識,本文旨在總結該配置檔案中重點的用法,以便日後查閱。下面是一個標準的AndroidManifes

MyBatis xml配置檔案

一、MyBatis 配置檔案基本結構        在使用mybatis框架時,首先匯入其對應的jar包,並進行相應的配置,所以得對配置檔案的每個引數都得了解。一個完全的mybatis配置檔案結構如下: <?xmlversion="1.0