---
# System prepended metadata

title: maven設定

---

# maven設定


[下載maven]
(https://maven.apache.org/download.cgi)
![](https://i.imgur.com/k7gZZMW.png)


設定maven
=====
- 環境變數
  - 使用者變數
![](https://i.imgur.com/oA0F4Z9.png)

先到使用者變數這裡，點新增
* 設定變數名稱
* 變數值就是maven解壓縮後的資料夾位置


  - 系統變數
![](https://i.imgur.com/xAMLQ5f.png)
點path >編輯>新增>貼上bin的路徑
![](https://i.imgur.com/eKBtF2v.png)


之後到cmd 打mvn -v


---
```
D:\datasource\apache-maven-3.9.1\conf
的settings.xml 這個檔案，接下來右鍵編輯，用nodepad++編輯，在mirror標籤上新增一個標籤

> 把maven 內的jar檔存在指定位置
<localRepository>D:\datasource\maven-download\repository</localRepository>
  <mirrors>

複製一個設定檔到maven-download    
    
D:\datasource\maven-download\repository
```

---

# 步驟

- new dynamic project (TestMaven)

- maven 專案右鍵>configure> convert to maven project 

- windows/preferences/maven/installations/add / 選解壓縮後的maven資料夾

![](https://i.imgur.com/UVWp597.png)
 
![](https://i.imgur.com/5x6HRPc.png)

- windows/preferences/maven/usersettings/D:\datasource\apache-maven-3.9.1\conf\settings.xml

![](https://i.imgur.com/GcHUwCF.png)




- pom檔新增dependencies標籤放jar檔

```
<packaging>war</packaging>
package 下面新建立dependencies標籤
<dependencies>

<dependency>
			<groupId>jakarta.servlet</groupId>
			<artifactId>jakarta.servlet-api</artifactId>
			<version>4.0.2</version>
			<scope>provided</scope>
		</dependency>
		<!-- https://mvnrepository.com/artifact/com.google.code.gson/gson -->
		<dependency>
			<groupId>com.google.code.gson</groupId>
			<artifactId>gson</artifactId>
			<version>2.9.0</version>
		</dependency>
</dependencies>

```
    
- 搜尋maven repository 
mvnrepository.com 這網站能下載jar檔的dependencies

https://mvnrepository.com/artifact/jakarta.servlet/jakarta.servlet-api/6.0.0

---



- 打V

![](https://i.imgur.com/zJ2M44M.png)



- maven壓縮黨內/conf資料夾/在mirror上面新增localRepository標籤
```
標籤內放路徑
<localRepository>D:\datasource\maven-download\repository</localRepository>
```

![](https://i.imgur.com/CEMVntD.png)


![](https://i.imgur.com/hPW6aw8.png)


- 上面的設定解釋了下面的截圖

- 複製一個設定檔到maven-download
  - 為什麼要複製一個檔案到新建立的maven-download資料夾?
  - 因為
![](https://i.imgur.com/RUS2mXx.png)
