명령행 모드 메이븐 프로젝트 생성하기

CLI(Command Line Interface) mode Maven project create

사전 조건 : maven이 설치되어있고 $maven_home/bin이 path에 등록되어 있다.

[localhost]$ mvn archetype:generate
......................................
1147: remote -> ru.yandex.qatools.camelot:camelot-plugin (-)
1148: remote -> se.vgregion.javg.maven.archetypes:javg-minimal-archetype (-)
1149: remote -> sk.seges.sesam:sesam-annotation-archetype (-)
1150: remote -> tk.skuro:clojure-maven-archetype (A simple Maven archetype for Clojure)
1151: remote -> tr.com.lucidcode:kite-archetype (A Maven Archetype that allows users to create a Fresh Kite project)
1152: remote -> uk.ac.rdg.resc:edal-ncwms-based-webapp (-)
Choose a number or apply filter (format: [groupId:]artifactId, case sensitive contains): 471: quickstart

Choose archetype:
1: remote -> com.agilejava.docbkx:docbkx-quickstart-archetype (-)
...................................................................
37: remote -> org.apache.isis.archetype:quickstart_wicket_restful_jdo-archetype (-)
38: remote -> org.apache.maven.archetypes:maven-archetype-quickstart (An archetype which contains a sample Maven project.)
39: remote -> org.apache.tapestry:quickstart (-)
Choose a number or apply filter (format: [groupId:]artifactId, case sensitive contains): 38: Enter

Choose org.apache.maven.archetypes:maven-archetype-quickstart version:
1: 1.0-alpha-1
2: 1.0-alpha-2
3: 1.0-alpha-3
4: 1.0-alpha-4
5: 1.0
6: 1.1
Choose a number: 6: 5
Downloading: http://repo.maven.apache.org/maven2/org/apache/maven/archetypes/maven-archetype-quickstart/1.0/maven-archetype-quickstart-1.0.jar
Downloaded: http://repo.maven.apache.org/maven2/org/apache/maven/archetypes/maven-archetype-quickstart/1.0/maven-archetype-quickstart-1.0.jar (5 KB at 3.9 KB/sec)
Downloading: http://repo.maven.apache.org/maven2/org/apache/maven/archetypes/maven-archetype-quickstart/1.0/maven-archetype-quickstart-1.0.pom
Downloaded: http://repo.maven.apache.org/maven2/org/apache/maven/archetypes/maven-archetype-quickstart/1.0/maven-archetype-quickstart-1.0.pom (703 B at 2.0 KB/sec)
Define value for property 'groupId': : net.iotinfra
Define value for property 'artifactId': : hellomvn
Define value for property 'version':  1.0-SNAPSHOT: :
Define value for property 'package':  net.iotinfra: : hellomvn
Confirm properties configuration:
groupId: net.iotinfra
artifactId: hellomvn
version: 1.0-SNAPSHOT
package: hellomvn
 Y: : Y
[INFO] ----------------------------------------------------------------------------
[INFO] Using following parameters for creating project from Old (1.x) Archetype: maven-archetype-quickstart:1.0
[INFO] ----------------------------------------------------------------------------
[INFO] Parameter: basedir, Value: /home/nextman/temp
[INFO] Parameter: package, Value: hellomvn
[INFO] Parameter: groupId, Value: net.iotinfra
[INFO] Parameter: artifactId, Value: hellomvn
[INFO] Parameter: packageName, Value: hellomvn
[INFO] Parameter: version, Value: 1.0-SNAPSHOT
[INFO] project created from Old (1.x) Archetype in dir: /home/nextman/temp/hellomvn
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 01:33 min
[INFO] Finished at: 2014-09-17T20:37:38+09:00
[INFO] Final Memory: 12M/35M
[INFO] ------------------------------------------------------------------------

하위 디렉토리에 hellomvn 프로젝트가 생성됨을 확인할 수 있다.

[localhost]$ ls hellomvn
pom.xml src

target을 지우고 컴파일 후 단위 테스트를 수행한다.

[localhost]$ cd hellomvn
[localhost]$ mvn clean test
[localhost]$ ls
pom.xml src target
[localhost]$ ls target
classes  surefire-reports  test-classes

target을 지우고 컴파일 후 단위 테스트를 수행 후 target 디렉토리에 jar 파일을 생성한다.

[localhost]$ mvn clean test package
[INFO] Scanning for projects...
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building hellomvn 1.0-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- maven-clean-plugin:2.5:clean (default-clean) @ hellomvn ---
[INFO] Deleting /home/nextman/temp/hellomvn/target
[INFO]
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ hellomvn ---
[WARNING] Using platform encoding (UTF-8 actually) to copy filtered resources, i.e. build is platform dependent!
[INFO] skip non existing resourceDirectory /home/nextman/temp/hellomvn/src/main/resources
[INFO]
[INFO] --- maven-compiler-plugin:2.5.1:compile (default-compile) @ hellomvn ---
[WARNING] File encoding has not been set, using platform encoding UTF-8, i.e. build is platform dependent!
[INFO] Compiling 1 source file to /home/nextman/temp/hellomvn/target/classes
[INFO]
[INFO] --- maven-resources-plugin:2.6:testResources (default-testResources) @ hellomvn ---
[WARNING] Using platform encoding (UTF-8 actually) to copy filtered resources, i.e. build is platform dependent!
[INFO] skip non existing resourceDirectory /home/nextman/temp/hellomvn/src/test/resources
[INFO]
[INFO] --- maven-compiler-plugin:2.5.1:testCompile (default-testCompile) @ hellomvn ---
[WARNING] File encoding has not been set, using platform encoding UTF-8, i.e. build is platform dependent!
[INFO] Compiling 1 source file to /home/nextman/temp/hellomvn/target/test-classes
[INFO]
[INFO] --- maven-surefire-plugin:2.12.4:test (default-test) @ hellomvn ---
[INFO] Surefire report directory: /home/nextman/temp/hellomvn/target/surefire-reports

-------------------------------------------------------
 T E S T S
-------------------------------------------------------
Running hellomvn.AppTest
Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.028 sec

Results :

Tests run: 1, Failures: 0, Errors: 0, Skipped: 0

[INFO]
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ hellomvn ---
[WARNING] Using platform encoding (UTF-8 actually) to copy filtered resources, i.e. build is platform dependent!
[INFO] skip non existing resourceDirectory /home/nextman/temp/hellomvn/src/main/resources
[INFO]
[INFO] --- maven-compiler-plugin:2.5.1:compile (default-compile) @ hellomvn ---
[INFO] Nothing to compile - all classes are up to date
[INFO]
[INFO] --- maven-resources-plugin:2.6:testResources (default-testResources) @ hellomvn ---
[WARNING] Using platform encoding (UTF-8 actually) to copy filtered resources, i.e. build is platform dependent!
[INFO] skip non existing resourceDirectory /home/nextman/temp/hellomvn/src/test/resources
[INFO]
[INFO] --- maven-compiler-plugin:2.5.1:testCompile (default-testCompile) @ hellomvn ---
[INFO] Nothing to compile - all classes are up to date
[INFO]
[INFO] --- maven-surefire-plugin:2.12.4:test (default-test) @ hellomvn ---
[INFO] Skipping execution of surefire because it has already been run for this configuration
[INFO]
[INFO] --- maven-jar-plugin:2.4:jar (default-jar) @ hellomvn ---
[INFO] Building jar: /home/nextman/temp/hellomvn/target/hellomvn-1.0-SNAPSHOT.jar
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 6.405 s
[INFO] Finished at: 2014-09-17T21:20:46+09:00
[INFO] Final Memory: 13M/31M
[INFO] ------------------------------------------------------------------------

[localhost]$ ls target
classes  hellomvn-1.0-SNAPSHOT.jar  maven-archiver  surefire-reports  test-classes

target/dependency 디렉토리에 의존 라이브러리를 복사한다.

[localhost]$ mvn clean dependency:copy-dependencies package

[localhost]$ ls target
classes  dependency  hellomvn-1.0-SNAPSHOT.jar  maven-archiver  surefire-reports  test-classes

[localhost]$ ls target/dependency/
junit-3.8.1.jar

dependency를 포함한 jar 생성참고:maven에서 dependency를 포함한 jar 생성하기
pom.xml에 다음 플러그인 추가

<plugin>
  <artifactId>maven-assembly-plugin</artifactId>
  <configuration>
    <archive>
      <manifest>
        <mainClass>fully.qualified.MainClass</mainClass>
      </manifest>
    </archive>
    <descriptorRefs>
      <descriptorRef>jar-with-dependencies</descriptorRef>
    </descriptorRefs>
  </configuration>
</plugin>

target 디렉토리에 build/finalName에 정의된 이름 뒤에 -jar-with-dependencies.jar를 붙인 jar 파일이 생성된다.

[localhost]$ mvn clean assembly:assembly
[localhost]$ ls target
archive-tmp  hellomvn-1.0-SNAPSHOT.jar                        maven-archiver    test-classes
classes      hellomvn-1.0-SNAPSHOT-jar-with-dependencies.jar  surefire-reports

댓글 남기기

이메일은 공개되지 않습니다. 필수 입력창은 * 로 표시되어 있습니다