각진 세상에 둥근 춤을 추자

웹 프로젝트 환경 구성 본문

Spring

웹 프로젝트 환경 구성

circle.j 2023. 7. 2. 22:43

1. 새 프로젝트 만들기 

 


2. build.gradle

 

(1) tomcat

https://mvnrepository.com/artifact/org.apache.tomcat.embed/tomcat-embed-core/8.5.42

// https://mvnrepository.com/artifact/org.apache.tomcat.embed/tomcat-embed-core
implementation 'org.apache.tomcat.embed:tomcat-embed-core:8.5.42'

https://mvnrepository.com/artifact/org.apache.tomcat.embed/tomcat-embed-jasper/8.5.42

// https://mvnrepository.com/artifact/org.apache.tomcat.embed/tomcat-embed-jasper
implementation 'org.apache.tomcat.embed:tomcat-embed-jasper:8.5.42'

 

(2) servlet

https://mvnrepository.com/artifact/javax.servlet/javax.servlet-api/4.0.1

// https://mvnrepository.com/artifact/javax.servlet/javax.servlet-api
implementation 'javax.servlet:javax.servlet-api:4.0.1'

 

(3) jstl

https://mvnrepository.com/artifact/javax.servlet/jstl/1.2

// https://mvnrepository.com/artifact/javax.servlet/jstl
implementation 'javax.servlet:jstl:1.2'

 

(4) logback

https://mvnrepository.com/artifact/ch.qos.logback/logback-classic/1.2.3

// https://mvnrepository.com/artifact/ch.qos.logback/logback-classic
testImplementation 'ch.qos.logback:logback-classic:1.2.3'
// https://mvnrepository.com/artifact/org.slf4j/slf4j-api
    implementation 'org.slf4j:slf4j-api:1.7.25'

 

 


3. WebApplicationServer.java

package org.example;

import org.apache.catalina.startup.Tomcat;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.File;

public class WebApplicationServer {

    private static final Logger log = LoggerFactory.getLogger(WebApplicationServer.class);
    public static void main(String[] args) throws Exception {

        String webappDirLocation = "webapps/";
        Tomcat tomcat = new Tomcat();
        tomcat.setPort(8080);

        tomcat.addWebapp("/", new File(webappDirLocation).getAbsolutePath());
        log.info("configuring app with basedir : {}", new File("./" + webappDirLocation).getAbsolutePath());

        tomcat.start();
        tomcat.getServer().await();
    }
}

 


4. webapps, WEB-INF 폴더 생성

(1) 프로젝트 - New - Directory 

 


5. Build Tools Setting

(1) Settings - Build, Execution, Deployment - Build Tools - Gradle : Gradle -> Intellij IDEA

 


6. Project Structure

(1) File - Project Structure - Modules - 프로젝트 main : 경로 build -> webapps/WEB-INF 변경 (뒤 production 지우기)