터미널이나 도스프롬프트에서 mvn archetype:generate 로 프로젝트를 생성한다.

yjpark@ubuntu:~/$mvn archetype:generate
[INFO] Scanning for projects...
[INFO] Searching repository for plugin with prefix: 'archetype'.
[INFO] ------------------------------------------------------------------------
[INFO] Building Maven Default Project
[INFO]    task-segment: [archetype:generate] (aggregator-style)
[INFO] ------------------------------------------------------------------------
[INFO] Preparing archetype:generate
.
.
Choose archetype:
1: internal -> appfuse-basic-jsf (AppFuse archetype for creating a web application with Hibernate, Spring and JSF)
2: internal -> appfuse-basic-spring (AppFuse archetype for creating a web application with Hibernate, Spring and Spring MVC)
.
.
15: internal -> maven-archetype-quickstart ()
.
.
Choose a number:  (1/2/3/4/5/6/7/8/9/10/11/12/13/14/15/16/17/18/19/20/21/22/23/24/25/26/27/28/29/30/31/32/33/34/35/36/37/38/39/40/41) 15: :

여기선 15를 입력하고 다음과 같이 나머지 항목도 입력한다.

Choose a number:  (1/2/3/4/5/6/7/8/9/10/11/12/13/14/15/16/17/18/19/20/21/22/23/24/25/26/27/28/29/30/31/32/33/34/35/36/37/38/39/40/41) 15: : 15
[INFO] artifact org.apache.maven.archetypes:maven-archetype-quickstart: checking for updates from central
Define value for groupId: : com.yjpark
Define value for artifactId: : MavenTest
Define value for version:  1.0-SNAPSHOT: :
Define value for package:  com.yjpark: :
Confirm properties configuration:
groupId: com.yjpark
artifactId: MavenTest
version: 1.0-SNAPSHOT
package: com.yjpark
 Y: : Y

정상적으로 완료되면 프로젝트의 구조는 다음과 같다.

MavenTest
|___pom.xml
|___src
          |___main
                     |___java
                             |___com
                                     |___yjpark
          |___test
                   |___java
                            |___com
                                     |___yjpark

- pom.xml 은  Project Object Model 정보를 담고 있는 파일로 프로젝트 정보나 dependency, plugin 등의 정보가 들어간다.
- /src/main/java  : 메인 자바 소스가 들어가는 곳
- /src/test/java : 유닛테스트용 자바 소스가 들어가는 곳

소스를 컴파일 할때는 다음과 같이 compile goal을 실행한다.

yjpark@ubuntu:~/MavenTest$mvn compile
[INFO] Scanning for projects...
[INFO] ------------------------------------------------------------------------
[INFO] Building MavenTest
[INFO]    task-segment: [compile]
[INFO] ------------------------------------------------------------------------
[INFO] [resources:resources]
[INFO] Using default encoding to copy filtered resources.
[INFO] [compiler:compile]
[INFO] Compiling 1 source file to /home/yjpark/MavenTest/target/classes
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESSFUL
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 5 seconds
[INFO] Finished at: Thu Jan 01 13:31:09 KST 2009
[INFO] Final Memory: 5M/10M
[INFO] ------------------------------------------------------------------------
yjpark@ubuntu:~/MavenTest$
디렉토리를 보면 target 디렉토리가 생성되었고 그곳에 클래스파일이 저장되어 있는것을 확인할 수 있다.

컴파일된 파일을 packaging할때는 다음과 같이 package goal을 실행한다.

yjpark@ubuntu:~/MavenTest$ mvn package
[INFO] Scanning for projects...
[INFO] ------------------------------------------------------------------------
[INFO] Building MavenTest
[INFO]    task-segment: [package]
[INFO] ------------------------------------------------------------------------
[INFO] [resources:resources]
[INFO] Using default encoding to copy filtered resources.
[INFO] [compiler:compile]
[INFO] Nothing to compile - all classes are up to date
[INFO] [resources:testResources]
[INFO] Using default encoding to copy filtered resources.
[INFO] [compiler:testCompile]
[INFO] Nothing to compile - all classes are up to date
[INFO] [surefire:test]
[INFO] Surefire report directory: /home/yjpark/MavenTest/target/surefire-reports

-------------------------------------------------------
 T E S T S
-------------------------------------------------------
Running com.yjpark.AppTest
Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.115 sec

Results :

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

[INFO] [jar:jar]
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESSFUL
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 7 seconds
[INFO] Finished at: Thu Jan 01 13:33:30 KST 2009
[INFO] Final Memory: 7M/12M
[INFO] ------------------------------------------------------------------------
yjpark@ubuntu:~/MavenTest$

위와같이 컴파일,유닛테스트까지 모두 수행하고 target디렉토리에 .jar파일이 생성된 것을 확인할 수 있다.

yjpark@ubuntu:~/MavenTest/target$ ls -al
합계 28
drwxr-xr-x 6 yjpark yjpark 4096 2009-01-01 13:33 .
drwxr-xr-x 4 yjpark yjpark 4096 2009-01-01 13:31 ..
-rw-r--r-- 1 yjpark yjpark 2100 2009-01-01 13:33 MavenTest-1.0-SNAPSHOT.jar
drwxr-xr-x 3 yjpark yjpark 4096 2009-01-01 13:31 classes
drwxr-xr-x 2 yjpark yjpark 4096 2009-01-01 13:33 maven-archiver
drwxr-xr-x 2 yjpark yjpark 4096 2009-01-01 13:33 surefire-reports
drwxr-xr-x 3 yjpark yjpark 4096 2009-01-01 13:33 test-classes
yjpark@ubuntu:~/MavenTest/target$


티스토리 툴바