memostack
article thumbnail
블로그를 이전하였습니다. 2023년 11월부터 https://bluemiv.github.io/에서 블로그를 운영하려고 합니다. 앞으로 해당 블로그의 댓글은 읽지 못할 수 도 있으니 양해바랍니다.
반응형

1. Maven 설치

본 글에서는 MacOS 환경에서 Maven을 설치하고, Homebrew를 이용한다.

<python />
# MacOSX brew install maven

 

설치 완료 후 버전 확인

<html />
$ mvn --version Apache Maven 3.6.3 (cecedd343002696d0abb50b32b541b8a6ba2883f) Maven home: /usr/local/Cellar/maven/3.6.3_1/libexec Java version: 14.0.1, vendor: N/A, runtime: /usr/local/Cellar/openjdk/14.0.1/libexec/openjdk.jdk/Contents/Home Default locale: ko_KR, platform encoding: UTF-8 OS name: "mac os x", version: "10.15.5", arch: "x86_64", family: "mac"

 

2. Maven으로 Java 프로젝트 생성하기

archetype:generate 옵션을 넣어 프로젝트를 생성한다.

<python />
$ mvn archetype:generate -DgroupId=com.exam -DartifactId=crawler -DarchetypeArtifactId=maven-archetype-quickstart -Dversion=1.0.0-SNAPSHOT ...중략... Confirm properties configuration: groupId: com.exam artifactId: crawler version: 1.0.0-SNAPSHOT package: com.exam Y: : Y # 위 내용 확인 후 'Y' 입력 [INFO] ------------------------------------------------------------------------ [INFO] BUILD SUCCESS [INFO] ------------------------------------------------------------------------ [INFO] Total time: 47.231 s [INFO] Finished at: 2020-09-11T19:04:15+09:00 [INFO] ------------------------------------------------------------------------

옵션 설명

  • -DgroupId: 프로젝트 패키지 (그룹 ID)
  • -DartifactId: 프로젝트 명 (아티팩트 ID)
  • -DarchetypeArtifactId: Maven 템플릿
  • -Dversion: 버전

 

3. 프로젝트 생성 확인

InteliJ에서 실행

 

4. Maven 패키징

clean package 옵션으로 실행한다.

  • clean: 이전에 만들어진 산출물을 삭제
  • pacakge: 컴파일 -> 테스트 -> 빌드 과정을 한번에 해준다.
<python />
$ mvn clean package
<python />
[INFO] Scanning for projects... [INFO] [INFO] --------------------------< com.exam:crawler >-------------------------- [INFO] Building crawler 1.0.0-SNAPSHOT [INFO] --------------------------------[ jar ]--------------------------------- [INFO] [INFO] --- maven-clean-plugin:2.5:clean (default-clean) @ crawler --- [INFO] Deleting /Users/hong/dev/crawler/target ...중략... [INFO] --- maven-surefire-plugin:2.12.4:test (default-test) @ crawler --- [INFO] Surefire report directory: /Users/hong/dev/crawler/target/surefire-reports Downloading from central: https://repo.maven.apache.org/maven2/org/apache/maven/surefire/surefire-junit3/2.12.4/surefire-junit3-2.12.4.pom Downloaded from central: https://repo.maven.apache.org/maven2/org/apache/maven/surefire/surefire-junit3/2.12.4/surefire-junit3-2.12.4.pom (1.7 kB at 1.5 kB/s) Downloading from central: https://repo.maven.apache.org/maven2/org/apache/maven/surefire/surefire-providers/2.12.4/surefire-providers-2.12.4.pom Downloaded from central: https://repo.maven.apache.org/maven2/org/apache/maven/surefire/surefire-providers/2.12.4/surefire-providers-2.12.4.pom (2.3 kB at 7.7 kB/s) Downloading from central: https://repo.maven.apache.org/maven2/org/apache/maven/surefire/surefire-junit3/2.12.4/surefire-junit3-2.12.4.jar Downloaded from central: https://repo.maven.apache.org/maven2/org/apache/maven/surefire/surefire-junit3/2.12.4/surefire-junit3-2.12.4.jar (26 kB at 55 kB/s) ------------------------------------------------------- T E S T S ------------------------------------------------------- Running com.exam.AppTest Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.006 sec Results : Tests run: 1, Failures: 0, Errors: 0, Skipped: 0 [INFO] [INFO] --- maven-jar-plugin:2.4:jar (default-jar) @ crawler --- [INFO] Building jar: /Users/hong/dev/crawler/target/crawler-1.0.0-SNAPSHOT.jar [INFO] ------------------------------------------------------------------------ [INFO] BUILD SUCCESS [INFO] ------------------------------------------------------------------------ [INFO] Total time: 3.527 s [INFO] Finished at: 2020-09-11T19:11:25+09:00 [INFO] ------------------------------------------------------------------------

 

패키징된 산출물은 target/{artifactID}-{version}.jar로 생성된다.

 

4.1. 오류 발생하면?

만약, 아래와 같은 오류가 발생하면 pom.xml에 Java의 source, target 버전을 넣어, Maven Compiler가 알 수 있도록 명시하자.

<python />
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.1:compile (default-compile) on project crawler: Compilation failure: Compilation failure: [ERROR] Source option 5 is no longer supported. Use 7 or later. [ERROR] Target option 5 is no longer supported. Use 7 or later.

 

pom.xml 에 아래 내용 추가

<python />
<properties> <maven.compiler.source>1.8</maven.compiler.source> <maven.compiler.target>1.8</maven.compiler.target> </properties>
반응형
블로그를 이전하였습니다. 2023년 11월부터 https://bluemiv.github.io/에서 블로그를 운영하려고 합니다. 앞으로 해당 블로그의 댓글은 읽지 못할 수 도 있으니 양해바랍니다.
profile

memostack

@bluemiv_mm

포스팅이 좋았다면 "좋아요❤️" 또는 "구독👍🏻" 해주세요!