maven만 사용하다가 이번엔 gradle을 사용해 보기로 했다.
gradle에서 제일 중요한 설정은 build.gradle 인것 같다.
1. build.gradle 설정
buildscript {
ext {
springBootVersion = '2.3.4.RELEASE'
}
repositories {
mavenCentral()
}
dependencies {
classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
}
}
apply plugin: 'java'
apply plugin: 'eclipse'
apply plugin: 'org.springframework.boot'
apply plugin: 'io.spring.dependency-management'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = '1.8'
repositories {
mavenCentral()
}
dependencies {
compile('org.springframework.boot:spring-boot-starter-web')
implementation 'org.springframework.boot:spring-boot-starter-web'
testCompile('org.springframework.boot:spring-boot-starter-test')
testImplementation 'org.springframework.boot:spring-boot-starter-test'
//lombok
compile "org.projectlombok:lombok:1.16.6"
//tomcat
compile('org.apache.tomcat.embed:tomcat-embed-jasper')
//jstl
compile('javax.servlet:jstl:1.2')
// MyBatis
compile("org.springframework.boot:spring-boot-starter-jdbc:2.0.1.RELEASE")
compile("mysql:mysql-connector-java:5.1.46")
compile("org.mybatis.spring.boot:mybatis-spring-boot-starter:1.3.1")
compile("org.mybatis:mybatis-spring:1.3.1")
compile("org.mybatis:mybatis:3.4.5")
}
2. Gradle > Refresh Gradle Project
- maven update 와 같은 역할을 한다.
3. application.properties (application.yaml) 설정
spring.mvc.view.prefix=/WEB-INF/views/
spring.mvc.view.suffix=.jsp
spring.mvc.static-path-pattern=/resources/**
#spring datasource begin
spring.datasource.driver-class-name=com.mysql.jdbc.Driver
spring.datasource.url=jdbc:mysql://localhost:3306/indp?serverTimezone=UTC&characterEncoding=UTF-8
spring.datasource.username=root
spring.datasource.password=root
#spring datasource end
server:
port: 80
spring:
mvc:
static-path-pattern: /resources/**
view:
prefix: /WEB-INF/views/
suffix: .jsp
datasource:
driver-class-name: com.mysql.jdbc.Driver
url: jdbc:mysql://localhost:3306/indp?useSSL=false
password: root
username: root
mybatis:
mapper-locations: classpath:mapper/**/**.xml
위와 같이 작성을 하고 cmd 창에서 build를 하면 jar파일이 생긴다.
이 jar 파일을 실행하면 tomcat이 embedded된 상태로 로컬에 올라간다.
build 및 jar 파일 실행 방법은 다음과 같다.
1. 프로젝트 경로에서 build 명령어 실행
./gradlew build
2. jar 파일 실행
java -jar .\build\libs\test-0.0.1-SNAPSHOT.jar
3. 다시 빌드할때는 다음 명령어를 실행 후 빌드 한다.
./gradlew init
'BackEND > Java' 카테고리의 다른 글
spring boot controller request multiple (0) | 2020.12.10 |
---|---|
spring boot gradle mybatis 연동 (0) | 2020.12.09 |
utc 날짜 파싱하는 방법 (0) | 2019.05.03 |
자주 쓰는 형변환 정리 (0) | 2017.11.30 |
UTC 날짜 파싱 (0) | 2017.11.30 |