๐Spring ์์กด์ฑ ๊ด๋ฆฌ
pom.xml
์คํ๋ง ๋ถํธ์ ๊ธฐ๋ณธ์ค์
- ๊ฐ์ฅ ๊ธฐ๋ณธ์ ์ผ๋ก ์คํ๋ง ๋ถํธ๋ฅผ ์คํ์ํค๊ธฐ ์ํด์๋ ์๋ ๋ด์ฉ์ด ํ์ํ๋ค.
<!--
Maven ์ค์ ์ Hierarchy๋ฅผ ๊ฐ์ง ์ ์๋ค.
๋ถ๋ชจ ํ๋ก์ ํธ๋ฅผ spring-boot-starter-parent๋ก ์ค์ ํ์ฌ "์์กด์ฑ ๊ด๋ฆฌ"๋ฅผ ์์๋ฐ๋๋ค.
-->
<!-- Inherit defaults from Spring Boot -->
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.2.4.RELEASE</version>
</parent>
<!--
์๋ dependancy์์ ๋ฒ์ ์ ๋ช
๊ธฐํ์ง ์์๋ ๋๋ ์ด์ ๋,
์ ๋ถ๋ชจ ํ๋ก์ ํธ์์ ํธํ๋๋ ๋ฒ์ ์ ๋ณด๊ฐ ์ด๋ฏธ ๋ช
์๋์ด์๊ธฐ ๋๋ฌธ์ด๋ค.
๋ฌผ๋ก ์ฌ๊ธฐ์ ์๋ก ๋ช
์ํด์ overrideํ ์๋ ์๋ค.
-->
<!-- Add typical dependencies for a web application -->
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
</dependencies>
<!-- Package as an executable jar -->
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
Parent POM(spring-boot-starter-parent)์ ์์กด์ฑ์ ์ฌ์ฉํ๊ณ ์ถ์ง ์๋ค๋ฉด?
<dependencyManagement>
๋ฅผ ํตํดScoped Dependency
๋ฅผ ์ฌ์ฉํ ์ ์๋ค. ๋ค๋ง spring-boot-starter-parent๋ ์คํ๋ง ๋ถํธ์ ์ต์ ํ๋ ๊ฐ์ ์ค์ (Java ๋ฒ์ , ์ธ์ฝ๋ฉ ์ค์ ๋ฑ)์ด ์ ์๋์ด ์์ด ๊ฐ๊ธ์ parent๋ฅผ ์ฌ์ฉํ๋ ๊ฒ์ด ์ข๋ค.
<dependencyManagement>
<dependencies>
<dependency>
<!-- Import dependency management from Spring Boot -->
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-dependencies</artifactId>
<version>2.3.1.RELEASE</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
๋ฒ์ ๋ง ๋ณ๊ฒฝํด๋ณด๊ณ ์ถ๋ค๋ฉด?
<dependancies>
์์ ๋ฒ์ ์ ๋ช ๊ธฐํ๋ ๊ฒ๊ณผ๋ ๋ค๋ฅธ ์ด์ผ๊ธฐ์ด๋ค. Parent์์์ ์์กด์ฑ ๊ด๋ฆฌ ๋ฒ์ ์ ๋ณ๊ฒฝํด๋ณด๋ ค๋ฉด ์๋์ ๊ฐ์ด<properties>
๋ด์์ ์ง์ ํ ์ ์๋ค.
<properties>
<spring.version>5.0.6.RELEASE</spring.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<java.version>11</java.version>
</properties>
์์กด์ฑ์ ์ถ๊ฐํ๋ ๋ฐฉ๋ฒ
https://mvnrepository.com/
์์ ๊ฒ์ํ ์ ์๋ค.npm
๊ณผpackage.json
๋งํผ ํธํ์ง๋ ์์ ๊ฒ ๊ฐ๋ค.
์คํ๋ง ๋ถํธ ํ๋ก์ ํธ๋ฅผ Jar๋ก ๋น๋ํ์ ๋์ ์์กด์ฑ
- ํ๋ก์ ํธ์ ์ถ๊ฐ๋ ์์กด์ฑ์ ํด๋นํ๋ Jar ํ์ผ๋ค์ด ๋ชจ๋ ํฌํจ๋์ฑ๋ก Jar๋ก ๋น๋๋๋ค.
- Jar ํ์ผ์ ์์ถํด์ ํด๋ณด๋ฉด
target/app/BOOT_INF/lib
์ ๋ผ์ด๋ธ๋ฌ๋ฆฌ๋ค์ด Jar ํํ๋ก ํฌํจ๋์ด ์๋ค. - ์ด๋ฌํ ๋ฐฉ์์
self-contained application
์ด๋ผ ํ๋ค.
Jar๋ก ๋ ๋ผ์ด๋ธ๋ฌ๋ฆฌ๋ฅผ ์ฌ์ฉํ๋ ๋ฐฉ๋ฒ
- Java์๋ ๊ธฐ๋ณธ์ ์ผ๋ก jar ๋ด์ ํ์ผ(nested jar)๋ค์ ์ฝ์ ์ ์๋ ํ์ค์ ์ธ ๋ฐฉ๋ฒ์ด ์๋ค. ํ์ง๋ง ๋ผ์ด๋ธ๋ฌ๋ฆฌ ์ฌ์ฉ์ ์ํด์๋ ๋ผ์ด๋ธ๋ฌ๋ฆฌ์ ์๋ง์ ํด๋์ค ๋ค์ ํ์ฉํด์ผ ํ๋ค.
- ์์ ์๋
uber jar
๋ฅผ ์ฌ์ฉํ์ผ๋ ์ด๋ค ๋ผ์ด๋ธ๋ฌ๋ฆฌ๋ฅผ ์ฌ์ฉํ๋์ง ์๊ธฐ ์ด๋ ต๊ณ , ์ด๋ฆ ์ถฉ๋์ ์ทจ์ฝํ๋ค. - ๊ทธ๋์ ์คํ๋ง ๋ถํธ๊ฐ Jar๋ฅผ ์ฝ๊ณ ์ฌ์ฉํ ์ ์๋
loader
์launcher
๋ฅผ ๋น๋์ ์ ๊ณตํด์ค๋ค.
์คํ ๊ฐ๋ฅํ Jar์ ๊ตฌ์กฐ
example.jar
|
+-META-INF
| +-MANIFEST.MF # ์คํ ๊ฐ๋ฅํ Jar์ ๋ฉํ ์ ๋ณด๋ฅผ ๋ด๊ณ ์๋ค. Main Class์ Start Class๊ฐ ์ ์๋์ด ์๋ค.
+-org
| +-springframework
| +-boot
| +-loader
| +-Launcher # Launcher์ด๋ค. ์คํ ๊ฐ๋ฅํ Jar์ ์คํ์ง์ (Main Class)๋ก ์ฌ์ฉ๋๋ค.
| +-jar
| +-JarFile # Loader์ด๋ค. nested jar๋ค์ ์ฝ์ ์ ์๋ ํ์ผ
+-BOOT-INF
+-classes
| +-mycompany
| +-project
| +-YourClasses.class
+-lib # ๋ผ์ด๋ธ๋ฌ๋ฆฌ(์์กด์ฑ)๋ค์ด Jar ํํ๋ก ํฌํจ๋์ด ์๋ค.
+-dependency1.jar
+-dependency2.jar
์คํ ๊ฐ๋ฅํ Jar์ ์๋ฏธ
- ์คํ ๊ฐ๋ฅํ Jar๋ ์คํ๋ง ๋ถํธ๋ฅผ ๋ ๋ฆฝ์ ์ผ๋ก ์คํ ๊ฐ๋ฅํ ์ดํ๋ฆฌ์ผ์ด์ ์ผ๋ก ๋ง๋ค์ด์ค๋ค.
- ์ด๋ ์คํ๋ง ๋ถํธ์ ์ฃผ์ ๋ชฉํ ์ค ํ๋์ด๋ค.
[1] ๋ฐฑ๊ธฐ์ , ์คํ๋ง ๋ถํธ ๊ฐ๋ ๊ณผ ํ์ฉ, 3๋ถ ์คํ๋ง ๋ถํธ ์๋ฆฌ