https://start.spring.io/
Spring Boot 3.3.0은 최소 Java 17 이상을 필요로 합니다.
Java 11을 사용하고 있는 경우, Spring Boot 2.7.x와 같은 이전 버전을 사용해야 합니다.
*Gradle과 Maven의 차이는 뭘까?
어떤 방식이 더 좋을지에 대한 궁금증!
Gradle과 Maven은 둘 다 Java 프로젝트의 빌드 및 관리를 위한 도구입니다.
둘 방식의 차이는 크게 파일 형태로 볼 수 있습니다.
- Maven은 선언형 구성으로 XML 파일(pom.xml)을 사용하여 프로젝트의 의존성, 빌드 설정 등을 선언합니다.
- Gradle은 스크립트 기반 구성으로 Groovy(build.gradle) 또는 Kotlin DSL(build.gradle.kts)를 사용하여 빌드 스크립트를 작성합니다.
[ pom.xml 예시 ]
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.example</groupId>
<artifactId>my-app</artifactId>
<version>1.0-SNAPSHOT</version>
<properties>
<maven.compiler.source>17</maven.compiler.source>
<maven.compiler.target>17</maven.compiler.target>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
[ build.gralde 예시 ]
plugins {
id 'org.springframework.boot' version '3.3.0'
id 'io.spring.dependency-management' version '1.0.15.RELEASE'
id 'java'
}
group = 'com.example'
version = '1.0-SNAPSHOT'
sourceCompatibility = '17'
repositories {
mavenCentral()
}
dependencies {
implementation 'org.springframework.boot:spring-boot-starter-web'
implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
runtimeOnly 'mysql:mysql-connector-java'
testImplementation 'org.springframework.boot:spring-boot-starter-test'
}
tasks.named('test') {
useJUnitPlatform()
}
Gradle은 변경된 파일만 빌드해주고 이전 빌드 결과를 재사용하기 때문에 전체를 빌드하는 Maven에 비해 효율적입니다.
때문에 성능 최적화가 중요하고, 유연한 빌드 구성이 필요한 대규모 프로젝트에서 특히 선호되지만,
Maven은 여전히 많은 오픈 소스 프로젝트와 기업에서 널리 사용되고 있으며, 특히 기존 레거시 프로젝트와의 호환성을 유지하기 위해 많이 사용되기 때문에 프로젝트의 성격에 따라 어떤 빌드 방식을 사용할지 결정하는 것이 좋습니다.
*Jar와 War 중 어떤 패키징방식을 사용해야할까?
Jar(Java ARchive)와 War(Web Application Archive) 패키징 방식은 Java 애플리케이션을 배포하는 데 사용되는 두 가지 주요 형식입니다.
- Jar: 일반 Java 애플리케이션의 실행 가능한 파일
- War: 웹 애플리케이션 배포를 위한 파일
Jar는 단순한 구조로 META-INF 디렉토리에 매니페스트 파일(MANIFEST.MF)을 포함하여, 애플리케이션의 메타데이터를 저장하고 컴파일된 Java클래스 파일(.class)과 관련 리소스 파일을 포함합니다.
War는 WEB-INF 디렉토리에 웹 애플리케이션의 설정 파일(web.xml), 라이브러리(lib 디렉토리), 클래스 파일(classes 디렉토리), 그리고 서블릿 클래스 파일을 포함할 뿐 아니라 HTML, CSS, JavaScript 파일 등 정적 리소스를 루트 디렉토리나 다른 디렉토리에 포함할 수 있습니다.
Jar는 java -jar <filename>.jar 명령어를 통해 독립적으로 실행할 수 있지만,
War는 독립적으로 실행되지 않아 웹서버나 서블릿 컨테이너에 배포하여 실행하여야 합니다.
Dependencies는 추후 pom.xml이나 build.gradle과 같은 빌드 파일에서 추가해줄 수 있기 때문에 넘어가도 되지만,
저는 주로 Lombok, Spring Web, Spring Boot DevTools, Spring Configuration Processor 라이브러리들을 먼저 추가해서 프로젝트를 생성해주도록 하겠습니다.
뭐라도하는 개발일지
tyan-8.tistory.com
모든 설정이 끝난 후 'GENERATE' 버튼을 눌러주면 zip 파일이 다운로드 되는데,
해당 zip파일을 원하는 workspace(디렉토리)에 옮겨준 뒤 zip 파일을 풀고 IDE에서 Open 해주시면 프로젝트 생성은 끝입니다!
GitHub - a-taeyeon/springboot-tistory-example
Contribute to a-taeyeon/springboot-tistory-example development by creating an account on GitHub.
github.com
'Web' 카테고리의 다른 글
Springboot Security는 어떤 역할을 할까? (0) | 2024.06.01 |
---|---|
[springboot] DB연결하기 - local MySQL+MyBatis (프로젝트 구조, 환경변수 설정, 연결확인) (0) | 2024.06.01 |
[Springboot] 프로젝트 생성 후 에러발생: project : > org.springframework.boot:org.springframework.boot.gradle.plugin:3.3.0 (0) | 2024.05.29 |
[spring-thymeleaf] th:field 사용시 th:value값 안나올 때 (0) | 2021.06.17 |
[spring] Spring Framework 개요 (0) | 2021.04.10 |