Notice
Recent Posts
Recent Comments
Link
개발 무지렁이
[Servlet] Eclipse에서 Maven (pom.xml) 기반의 서블릿 프로젝트 기본 설정 및 구조파악 본문
Backend/Servlet & JSP
[Servlet] Eclipse에서 Maven (pom.xml) 기반의 서블릿 프로젝트 기본 설정 및 구조파악
Gaejirang-e 2023. 8. 19. 15:54
𐂂 Create a Dynamic Web Project
[Project name]: 입력
[Target runtime] > [New Runtime] > Apache Tomcat v9.0
[Drag project] > Tomcat v9.0
Next > [Tomcat installation directory] > Browse...
[JRE] > [Installed JREs...]
jre(default) > Remove
Add... > Standard VM
Directory... > [Java 경로 선택] > Finish
[JRE] > jdk-11 > Finish
Next > Add Folder...
Next > ✔️ Generate web.xml deployment descriptor > Finish
[Target runtime] > [New Runtime] > Apache Tomcat v9.0
[Drag project] > Tomcat v9.0
Next > [Tomcat installation directory] > Browse...
[JRE] > [Installed JREs...]
jre(default) > Remove
Add... > Standard VM
Directory... > [Java 경로 선택] > Finish
[JRE] > jdk-11 > Finish
Next > Add Folder...
Next > ✔️ Generate web.xml deployment descriptor > Finish
➼ 🦔 Server 설정 [Servers Tab]
No servers are available. Click this link to create a new server...
😺Tomcat v9.0 Server
Next > [Available] 프로젝트 이동
Add > [Configured] > Finish
Tomcat v9.0 Server at localhost [Stopped, Republish] 더블클릭🖱️
[Port Name] HTTP/1.1 [Port Number 변경]
😺Tomcat v9.0 Server
Next > [Available] 프로젝트 이동
Add > [Configured] > Finish
Tomcat v9.0 Server at localhost [Stopped, Republish] 더블클릭🖱️
[Port Name] HTTP/1.1 [Port Number 변경]
🦣 Maven Project로 변환
[Project Explorer]
프로젝트 우클릭🖱️
Configure > Convert to Maven Project > [Packaging] War > Finish
프로젝트 우클릭🖱️
Configure > Convert to Maven Project > [Packaging] War > Finish
한글 설정
[File] > [Properties] > [Resource]
[Text file encoding] > [Other] UTF-8 > Apply and Close
[Window] > [Proferences]
> [Web]
> CSS Files > [Encoding] ISO 10646/Unicode(UTF-8) > Apply
> HTML Files > [Encoding] ISO 10646/Unicode(UTF-8) > Apply
> JSP Files > [Encoding] ISO 10646/Unicode(UTF-8) > Apply and Close
[Text file encoding] > [Other] UTF-8 > Apply and Close
[Window] > [Proferences]
> [Web]
> CSS Files > [Encoding] ISO 10646/Unicode(UTF-8) > Apply
> HTML Files > [Encoding] ISO 10646/Unicode(UTF-8) > Apply
> JSP Files > [Encoding] ISO 10646/Unicode(UTF-8) > Apply and Close
프로젝트 변경사항 감지
[Window] > [Preferences]
[General] > [Workspace] > ✔️ Refresh using native hooks or polling > Apply
프로젝트 변경사항을 감지하고, 업데이트 하는 방식을 설정하는 옵션
native hooks(자체 후킹), 파일시스템의 변경사항을 감지
🧸 후킹(Hooking):
프로그램의 동작을 감시하며,
프로그램에서 발생하는 이벤트나 함수호출을 가로채서 조작하는 것을 말한다.
🧸 폴링(Polling)
주기적으로 파일시스템의 상태나 데이터를 검사하거나 가져오는 방식을 말한다.
[General] > [Workspace] > ✔️ Refresh using native hooks or polling > Apply
프로젝트 변경사항을 감지하고, 업데이트 하는 방식을 설정하는 옵션
native hooks(자체 후킹), 파일시스템의 변경사항을 감지
🧸 후킹(Hooking):
프로그램의 동작을 감시하며,
프로그램에서 발생하는 이벤트나 함수호출을 가로채서 조작하는 것을 말한다.
🧸 폴링(Polling)
주기적으로 파일시스템의 상태나 데이터를 검사하거나 가져오는 방식을 말한다.
resources(접속 및 설정 정보) 및 test 폴더 만들기
프로젝트 우클릭🖱️
[Build Path] > [Configure Build Path...]
[Source Tab] > [Add Folder...]
[Create New Folder...] > [resouces] 입력 > Finish > OK
⚠️ resources와 src는 ClassPath에 세팅되어있는 영역이다.
[Source Tab] > [Add Folder...]
[Create New Folder...] > [test] 입력 > Finish > OK
> Apply and Close
[🗂️Java Resources] > test 폴더 우클릭🖱️ > New > other...
📂Java > JUnit > JUnit Test Case
> Next > New JUnit 4 test > [Name] 입력 > Finish
> OK
[Build Path] > [Configure Build Path...]
[Source Tab] > [Add Folder...]
[Create New Folder...] > [resouces] 입력 > Finish > OK
⚠️ resources와 src는 ClassPath에 세팅되어있는 영역이다.
[Source Tab] > [Add Folder...]
[Create New Folder...] > [test] 입력 > Finish > OK
> Apply and Close
[🗂️Java Resources] > test 폴더 우클릭🖱️ > New > other...
📂Java > JUnit > JUnit Test Case
> Next > New JUnit 4 test > [Name] 입력 > Finish
> OK
WEB-INF 폴더
웹 애플리케이션의 보안과 구조를 관리하는데 중요한 폴더이다.
web.xml 및 설정파일들: 웹 애플리케이션의 구성정보를 정의(서블릿 매핑, 리스너)
classes: 웹 애플리케이션에 포함된 자바 클래스 파일 위치(서블릿 필터 리스너 등의 컴포넌트)
lib: 웹 애플리케이션에서 사용하는 라이브러리JAR 파일 위치
web.xml 및 설정파일들: 웹 애플리케이션의 구성정보를 정의(서블릿 매핑, 리스너)
classes: 웹 애플리케이션에 포함된 자바 클래스 파일 위치(서블릿 필터 리스너 등의 컴포넌트)
lib: 웹 애플리케이션에서 사용하는 라이브러리JAR 파일 위치
pom.xml 의존성 추가
lombok🌶️ / mysql / json / log4j / mybatis / jstl
</build>와 </project> 사이
<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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>shopping_mall</groupId>
<artifactId>shopping_mall</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>war</packaging>
<build>
<sourceDirectory>src</sourceDirectory>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
<configuration>
<release>11</release>
</configuration>
</plugin>
<plugin>
<artifactId>maven-war-plugin</artifactId>
<version>3.2.3</version>
<configuration>
<warSourceDirectory>webapp</warSourceDirectory>
</configuration>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.18.24</version>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>8.0.17</version>
</dependency>
<dependency>
<groupId>org.json</groupId>
<artifactId>json</artifactId>
<version>20230227</version>
</dependency>
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>1.2.17</version>
</dependency>
<dependency>
<groupId>org.mybatis</groupId>
<artifactId>mybatis</artifactId>
<version>3.4.6</version>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>jstl</artifactId>
<version>1.2</version>
</dependency>
</dependencies>
</project>
🦉 pom.xml 분석
<warSourceDirectory> 요소는 웹 애프리케이션 프로젝트의 리소스 파일들이
위치한 📂 디렉터리 경로를 지정하는데 사용한다.
<groupId>: Maven에서 프로젝트를 식별하기 위해 사용되는 식별자이며,
조직의 도메인 이름을 역순으로 나열하여 생성한다.
<artifactId>: 프로젝트 빌드 결과물인 artifact의 이름을 지정하는 식별자이며,
보통 JAR파일(라이브러리), WAR파일 등을 가리킨다.
artifactId는 보통 프로젝트 이름을 나타낸다.
🧸 WAR(Web ARchive)
WAR 패키징은 자바 웹 애플리케이션을 배포하기 위한 표준 형식 중 하나이다.
(모든 컴포넌트와 리소스를 하나의 아카이브 파일로 묶어서 패키징하는 것을 말한다.)
이 형식으로 패키징된 웹 애플리케이션을 빌드할 때
해당 디렉터리에 있는 파일들이 웹 애플리케이션의 리소스로 포함되게 된다.
<warSourceDirectory> 요소는 웹 애프리케이션 프로젝트의 리소스 파일들이
위치한 📂 디렉터리 경로를 지정하는데 사용한다.
<groupId>: Maven에서 프로젝트를 식별하기 위해 사용되는 식별자이며,
조직의 도메인 이름을 역순으로 나열하여 생성한다.
<artifactId>: 프로젝트 빌드 결과물인 artifact의 이름을 지정하는 식별자이며,
보통 JAR파일(라이브러리), WAR파일 등을 가리킨다.
artifactId는 보통 프로젝트 이름을 나타낸다.
🧸 WAR(Web ARchive)
WAR 패키징은 자바 웹 애플리케이션을 배포하기 위한 표준 형식 중 하나이다.
(모든 컴포넌트와 리소스를 하나의 아카이브 파일로 묶어서 패키징하는 것을 말한다.)
이 형식으로 패키징된 웹 애플리케이션을 빌드할 때
해당 디렉터리에 있는 파일들이 웹 애플리케이션의 리소스로 포함되게 된다.
[Dependencies Tab] > 의존성 추가 확인
[Project Explorer]
프로젝트 우클릭🖱️
Maven > Update Project > Ok
[Project Explorer]
프로젝트 우클릭🖱️
Maven > Update Project > Ok
'Backend > Servlet & JSP' 카테고리의 다른 글
[Servlet] 클라이언트, 톰캣(Tomcat), DispatcherServlet으로 이어지는 HTTP 요청처리 (0) | 2023.08.20 |
---|---|
[Servlet] 진입점 컨트롤러(DispatcherServlet)와 인터페이스 Controller 및 ModelAndView 객체 (0) | 2023.04.26 |
[Servlet] 사전/사후 처리를 위한 Filter 인터페이스 (0) | 2023.04.25 |
[JSP] 쉽게 사용하기 위한 표현언어 EL과 JSTL (0) | 2023.04.24 |
[JSP] 액션태그 include와 include 지시자 (0) | 2023.04.24 |