缺少 Eclipse 的 Maven settings.xml 文件? 如果您需要 Work 和 Personal Workspace 的兩個 settings.xml 文件怎麼辦?
已發表: 2018-02-19 您是否在開發人員工作站上運行多個 Eclipse 環境? 還是在您的筆記本電腦上? 我願意。 讓我們考慮一個場景,其中two different Eclipse workspace
具有different custom maven
設置。
為什麼會這樣? 讓我們了解一下。
- 如果您的
Work
開發環境或框架是基於 Eclipse 的呢? 在公司環境中,您所需項目的所有 .jar 文件都必須位於private
存儲庫中,並且您有自定義settings.xml
文件,其中包含非常特定的存儲庫。 - 另一方面,對於標準的 eclipse/maven 使用——所有
public
maven 存儲庫都免費提供給我們,沒有任何限制。
當然,我們需要兩個不同的settings.xml
文件來實現上述用途。 如果您不熟悉 maven 和 eclipse 設置,請按照以下步驟在筆記本電腦/台式機上設置 maven 正確方式。
NOTE:
如何在 Eclipse 中添加 settings.xml? 除非您想更改默認設置,否則 settings.xml 不是必需的(因此不會在~/.m2
文件夾中自動創建)。 在我們的案例中,我們確實為work
和personal
工作區設置了不同的設置。
如果您還有以下問題,那麼您來對地方了:
- eclipse - 為什麼沒有 maven settings.xml 文件?
- 如何從 Eclipse 鏈接到我的 settings.xml 文件
- 使用 Eclipse 和 Maven 開發項目
- m2e 用戶 – settings.xml 文件在哪裡?
- maven settings.xml文件下載
- eclipse嵌入式maven
- eclipse maven settings.xml 位置
什麼是 settings.xml 文件?
settings.xml
是一個文件,它提供了maven
的所有配置,這些配置在您的 maven 項目的 pom.xml 文件中內部引用。 當您將依賴項添加到pom.xml
文件中時,maven 會在內部下載所需的 .jar 文件並將其放在 settings.xml 文件中提到的文件夾下。
我在哪裡可以找到 settings.xml 文件?
- Windows 機器:C:\Users\ashah\.m2\settings.xml
- 在 Mac OS X 上:/home/ashah/.m2/settings.xml
settings.xml 文件的默認內容是什麼?
只需使用您系統的用戶名更新以下文件中的<UserName>
。 這是一個Maven settings.xml 下載文件。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 |
<? xml version = "1.0" encoding = "UTF-8" ?> < ! -- | This is the configuration file for Maven . It can be specified at two levels : | | 1. User Level . This settings . xml file provides configuration for a single user , | and is normally provided in $ { user . home } / . m2 / settings . xml . | | NOTE : This location can be overridden with the CLI option : | | - s / path / to / user / settings . xml | | 2. Global Level . This settings . xml file provides configuration for all Maven | users on a machine ( assuming they 're all using the same Maven | installation). It' s normally provided in | $ { maven . home } / conf / settings . xml . | | NOTE : This location can be overridden with the CLI option : | | - gs / path / to / global / settings . xml | | | -- > < 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 http://maven.apache.org/xsd/settings-1.0.0.xsd" > < ! -- Change username in below line -- > < localRepository > / Users / ashah / . m2 / repository < / localRepository > < interactiveMode > true < / interactiveMode > < offline > false < / offline > < pluginGroups > < ! -- pluginGroup | Specifies a further group identifier to use for plugin lookup . < pluginGroup > com . your . plugins < / pluginGroup > -- > < / pluginGroups > < proxies > < ! -- < proxy > < id > optional < / id > < active > true < / active > < protocol > http < / protocol > < username > proxyuser < / username > < password > proxypass < / password > < host > proxy . host . net < / host > < port > 80 < / port > < nonProxyHosts > local . net | some . host . com < / nonProxyHosts > < / proxy > -- > < / proxies > < servers > < ! -- < server > < id > deploymentRepo < / id > < username > crunchify < / username > < password > crunchify < / password > < / server > -- > < / servers > < mirrors > < ! -- < mirror > < id > mirrorId < / id > < mirrorOf > repositoryId < / mirrorOf > < name > mirror description < / name > < url > http : //my.repository.com/repo/path</url> < / mirror > -- > < / mirrors > < profiles > < / profiles > < / settings > |
以上是 maven eclipse 的示例 settings.xml。

如何將兩個不同的 settings.xml 文件用於個人和工作相關的存儲庫?
第1步
- 轉到
~/.m2
文件夾 - 放置工作相關的
settings.xml
文件並提供localRepository
路徑: - <localRepository>/Users/<UserName>/.m2/
work
</localRepository>
第2步
- 轉到
~/.m2
文件夾 - 放置本地eclipse相關
crunchify-settings.xml
文件並提供localRepository
路徑: - <localRepository>/Users/<用戶名>/.m2/
repository
</localRepository>
什麼是您沒有正確的 settings.xml 文件?
Eclipse 拋出許多不同的錯誤:
一旦你有正確的 settings.xml 文件。 嘗試執行以下步驟,所有錯誤都應該消失。
- 點擊
Project
菜單 - 單擊
Clean...
並清理您的項目 - 右鍵單擊項目
- 點擊
Maven
- 單擊
Update Project...
(下圖)
而已。 執行上述步驟後,Eclipse 將在 settings.xml 文件中提供的路徑下導入所有項目依賴項。 導入過程完成後,您不應在 Eclipse 中看到任何編譯問題。 根據您的項目依賴項和 Internet 下載速度,依賴項導入過程可能需要大約 5 分鐘到 30 分鐘。