> For the complete documentation index, see [llms.txt](https://docs.sysout.co.kr/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.sysout.co.kr/web/back-end/what-is-spring-framework/spring-environment-setting/maven-location-setting.md).

# Maven 저장소 위치 설정

## Maven 저장소 위치 변경

Maven 의존성 저장 폴더는 <mark style="color:blue;">Windows</mark>의 경우 <mark style="color:red;">`C:\Users\계정명\.m2`</mark> 로 설정되어 있다. 필요하다면 Maven의 다운로드 폴더 위치를 변경할 수 있는데 변경해야 하는 상황은 다음과 같다.

* <mark style="color:red;">`java.util.zip.ZipException`</mark> 이 자주 발생하는 경우

모든 Eclipse 계열 프로그램은 내부적으로 maven 의존성을 사용하기 때문에 충돌이 발생하여 기존의 파일들이 깨지는 경우가 발생할 수 있다. 이 때 발생하는 예외가 <mark style="color:red;">`java.util.zip.ZipException`</mark> 이다.

## 저장소 변경을 위한 설정 파일

저장소 변경을 위해서는 설정 파일이 필요하다. 일반적인 경우 `.m2` 폴더에 있으며, 없을 경우 직접 만들어도 무방하다.

### setting.xml

설정 문서의 형태는 다음과 같다.

파일 이름은 자유롭게 사용 가능하며 `xml` 형식으로 저장하면 된다.

```markup
<?xml version="1.0" encoding="UTF-8"?>
<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">

    <localRepository>저장소 위치 설정</localRepository>

</settings>
```

공식 사이트의 설명을 보고 싶을 경우 [이곳](https://maven.apache.org/settings.html)을 눌러서 확인할 수 있다.

저장소 위치 설정 부분에 사용하고 싶은 경로를 작성한 뒤 원하는 위치에 저장한다.(파일을 찾아서 지정할 것이므로 위치는 무관하다) 이 문서에서는 `D:/maven` 위치에 설정을 진행한다.

## 설정 파일 작성

`D:/maven` 경로로 maven 작업 경로를 변경하기 위한 설정 파일은 다음과 같다.

> maven-setting.xml

```markup
<?xml version="1.0" encoding="UTF-8"?>
<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">

  <localRepository>D:/maven</localRepository>

</settings>
```

폴더는 만들어둘 필요가 없다.

## 이클립스 설정

이클립스에서는 다음 절차에 따라 진행한다.

1. \[Window] → \[Preferences] 메뉴 선택
2. `maven` 검색
3. \[Maven] → \[User Settings] 선택
4. \[User Settings] → \[Browse] 선택
5. 설정 파일 지정
6. 설정 완료

![maven 검색](https://4208234536-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-M_TNZwLuHV9ipYLbvRq%2F-Mc87iVqo2trW-9hMgwx%2F-Mc889yRpyXwUwJRy-S-%2Fimage.png?alt=media\&token=383b9cb3-1682-4807-a757-dfef0b789711)

![찾기버튼 누르기](https://4208234536-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-M_TNZwLuHV9ipYLbvRq%2F-Mc87iVqo2trW-9hMgwx%2F-Mc88E8g6U0_g--GK96T%2Fimage.png?alt=media\&token=cd5642cf-1673-400f-a2a0-97c18dc73565)

![파일 찾기](https://4208234536-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-M_TNZwLuHV9ipYLbvRq%2F-Mc87iVqo2trW-9hMgwx%2F-Mc88JiG3ZIvoz6yriMT%2Fimage.png?alt=media\&token=46ea3d05-aa2f-4ea6-a0e8-dcf47a855150)

![파일 지정](https://4208234536-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-M_TNZwLuHV9ipYLbvRq%2F-Mc87iVqo2trW-9hMgwx%2F-Mc88LE0eGV91f9qRWh6%2Fimage.png?alt=media\&token=7f4cef83-b278-4255-b4f6-6279d83d5749)

![설정 완료](https://4208234536-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-M_TNZwLuHV9ipYLbvRq%2F-Mc87iVqo2trW-9hMgwx%2F-Mc88MTAfHjjVB1Zo_uF%2Fimage.png?alt=media\&token=b2f1d672-d0c8-4102-9345-b1ae01c84875)
