본문 바로가기
카테고리 없음

MAVEN

by cook_code 2023. 4. 25.
반응형

MAVEN이란?

Maven은 자바용 프로젝트 관리를 위한 도구
-- apache software foundation에서 개발한 java 기반 프로젝트 관리
-- 프로젝트의 컴파일, 빌드, 수행 및 테스트
-- 서버 측 deploy 자원과 라이브러리 관리

MAVEN 프로젝트 생성

maven, maven archetype 설정
org.apache.maven.archetypes:maven-archetype-webapp

groupId : 회사 이름
artifactId : 프로젝트 이름

1. pom.xml 자동 생성


2. dependency 추가
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>4.0.1</version>
</dependency>

3. 메인 폴더 new - directory - java 자동 생성


4. 패키지 생성 - 서블릿클래스 만들기


5. httpservlet 참조, 오버라이드 doget()


6. resp.setContentType("text/html;charset:UTF-8");
PrintWriter out = resp.getWriter();
out.println("Hello,there!!");
out.close();


7. 서블릿클래스를 등록하는 방법 2가지
7-1. pom.xml 파일에 명시하기 (한 세트)
<servlet>
<servlet-name>hello-servlet</servlet-name>
<servlet-class>org.example.HelloServlet</servlet-class>
</servlet>
<!-- 어떤 url이름을 호출해서 사용자에게 보여줄건지 -->
<servlet-mapping>
<servlet-name>hello-servlet</servlet-name>
<url-pattern>HelloServlet</url-pattern>
</servlet-mapping>
7-2. 어노테이션 활용하기
@WebServlet("/HelloServlet2")
서블렛 클래스 위에 작성


8. 톰캣 서버에 배포, 실행
8-1. add configuration - tomcat - local
8-2. 이름설정, 포트번호 확인, deployment 탭 클릭
8-3. +버튼 - 프로젝트이름: war exploded (압축 해제된 폴더)
8-4. 빌드와 서버와 프로젝트 연결은 같지 않다.

작업 폴더로 output 폴더를 지정해서 새로고침 시 바뀐 내용을 바로 볼 수 있도록 하기
- edit configuration
- output 경로 찾기
- src - webapp 폴더로 설정

settings.xml

- 메이븐 빌드 툴과 관련된 설정 파일

pom.xml

- 메이븐 기능을 이용하기 위한 파일

- 프로젝트마다 1개 존재하며, 프로젝트의 설정과 의존성을 확인할 수 있다.

MAVEN REPOSITORY

프로젝트와 의존 관계에 있는 라이브러리들 다운받을 수 있는 사이트

링크: https://mvnrepository.com/

<dependencies>
<!-- https://mvnrepository.com/artifact/org.mybatis/mybatis -->
<dependency>
    <groupId>org.mybatis</groupId>
    <artifactId>mybatis</artifactId>
    <version>3.5.10</version>
</dependency>
<!-- https://mvnrepository.com/artifact/javax.servlet/jstl -->
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>jstl</artifactId>
<version>1.2</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.json/json -->
<dependency>
<groupId>org.json</groupId>
<artifactId>json</artifactId>
<version>20220320</version>
</dependency>
<!-- https://mvnrepository.com/artifact/com.oracle.database.jdbc/ojdbc6 -->
<dependency>
    <groupId>com.oracle.database.jdbc</groupId>
    <artifactId>ojdbc6</artifactId>
    <version>11.2.0.4</version>
</dependency>
</dependencies>
반응형