본문 바로가기

Language/Java

[Spring] Intellij Maven & Spring 프로젝트 생성(jsp기반 프로젝트)

※ Intellij Community 버전의 경우 Spring Project를 IDE내에서 바로 생성할 수 없다. 그래서 Maven 프로젝트 생성 후 Spring dependency를 추가해줘야 한다.

 

Maven 프로젝트 생성

- File → New → Project... 클릭  → Maven Archetype 클릭

- Name, Location, JDK 를 작성 및 선택

- Archetype은 'maven-archetype-webapp' 선택

- Advanced Settings 클릭 후 GroupId, ArtifactId 작성

[예시]

GroupId  : com.{회사명}

ArtifactId : {프로젝트명}

com.company.tool

 

pom.xml 수정(Dependency 추가)

[기존 pom.xml]

 

[수정 후 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/maven-v4_0_0.xsd">
  <modelVersion>4.0.0</modelVersion>

  <groupId>com.company</groupId>
  <artifactId>tool</artifactId>
  <packaging>war</packaging>
  <version>1.0-SNAPSHOT</version>
  <name>tool Maven Webapp</name>
  <url>http://maven.apache.org</url>

  <dependencies>
    <!-- JUnit for testing -->
    <dependency>
      <groupId>junit</groupId>
      <artifactId>junit</artifactId>
      <version>3.8.1</version>
      <scope>test</scope>
    </dependency>

    <!-- Servlet API for JSP support -->
    <dependency>
      <groupId>javax.servlet</groupId>
      <artifactId>javax.servlet-api</artifactId>
      <version>4.0.1</version>
      <scope>provided</scope>
    </dependency>

    <!-- JSTL for JSP -->
    <dependency>
      <groupId>javax.servlet.jsp</groupId>
      <artifactId>javax.servlet.jsp-api</artifactId>
      <version>2.3.3</version>
      <scope>provided</scope>
    </dependency>

    <dependency>
      <groupId>javax.servlet</groupId>
      <artifactId>jstl</artifactId>
      <version>1.2</version>
    </dependency>

    <!-- Spring Web for MVC -->
    <dependency>
      <groupId>org.springframework</groupId>
      <artifactId>spring-webmvc</artifactId>
      <version>5.3.24</version>
    </dependency>

    <!-- Spring Core for basic Spring functionality -->
    <dependency>
      <groupId>org.springframework</groupId>
      <artifactId>spring-core</artifactId>
      <version>5.3.24</version>
    </dependency>

    <!-- Spring Context for managing beans -->
    <dependency>
      <groupId>org.springframework</groupId>
      <artifactId>spring-context</artifactId>
      <version>5.3.24</version>
    </dependency>
  </dependencies>

  <build>
    <finalName>tool</finalName>
  </build>
</project>

 

Dependency 추가 후 프로젝트 확인

 

※ pom.xml에 빨간줄이 떠있다면 Maven 탭의 아래 버튼을 클릭하고 프로젝트를 껐다 켜주자