메이븐을 이용하면 의존성을 가진 라이브러리들까지 손쉽게 다운로드 받아서 프로젝트를 생성할 수가 있다.
2줄의 명령어만 넣어주면 된다.
스트럿츠 archetype을 생성하는 방법은 두 종류가 있다. 둘 중 마음에 드는 방법을 선택한다.
1.1. 메이븐의 archetype을 이용하여 스트럿츠 프로젝트를 생성(generate)한다.
생성 과정 기록 :
HoneyBook:dreaminfra ihoneymon$ mvn archetype:generate -DarchetypeCatalog=http://struts.apache.org/
[INFO] Scanning for projects...
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building Maven Stub Project (No POM) 1
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] >>> maven-archetype-plugin:2.1:generate (default-cli) @ standalone-pom >>>
[INFO]
[INFO] <<< maven-archetype-plugin:2.1:generate (default-cli) @ standalone-pom <<<
[INFO]
[INFO] --- maven-archetype-plugin:2.1:generate (default-cli) @ standalone-pom ---
[INFO] Generating project in Interactive mode
[INFO] No archetype defined. Using maven-archetype-quickstart (org.apache.maven.archetypes:maven-archetype-quickstart:1.0)
//원하는 유형을 선택하고 groupId, articleId 를 임의에 따라 지정한다.
Choose archetype:
1: http://struts.apache.org/ -> org.apache.struts:struts2-archetype-blank (Struts 2 Archetypes - Blank)
2: http://struts.apache.org/ -> org.apache.struts:struts2-archetype-convention (Struts 2 Archetypes - Blank Convention)
3: http://struts.apache.org/ -> org.apache.struts:struts2-archetype-dbportlet (Struts 2 Archetypes - Database Portlet)
4: http://struts.apache.org/ -> org.apache.struts:struts2-archetype-plugin (Struts 2 Archetypes - Plugin)
5: http://struts.apache.org/ -> org.apache.struts:struts2-archetype-portlet (Struts 2 Archetypes - Portlet)
6: http://struts.apache.org/ -> org.apache.struts:struts2-archetype-starter (Struts 2 Archetypes - Starter)
Choose a number or apply filter (format: [groupId:]artifactId, case sensitive contains): : 1
Define value for property 'groupId': : StudyStruts
Define value for property 'artifactId': : StudyStruts
Define value for property 'version': 1.0-SNAPSHOT: :
Define value for property 'package': StudyStruts: :
Confirm properties configuration:
groupId: StudyStruts
artifactId: StudyStruts
version: 1.0-SNAPSHOT
package: StudyStruts
Y: : y
[INFO] ----------------------------------------------------------------------------
[INFO] Using following parameters for creating project from Archetype: struts2-archetype-blank:2.2.1
[INFO] ----------------------------------------------------------------------------
[INFO] Parameter: groupId, Value: StudyStruts
[INFO] Parameter: artifactId, Value: StudyStruts
[INFO] Parameter: version, Value: 1.0-SNAPSHOT
[INFO] Parameter: package, Value: StudyStruts
[INFO] Parameter: packageInPathFormat, Value: StudyStruts
[INFO] Parameter: package, Value: StudyStruts
[INFO] Parameter: version, Value: 1.0-SNAPSHOT
[INFO] Parameter: groupId, Value: StudyStruts
[INFO] Parameter: artifactId, Value: StudyStruts
[INFO] project created from Archetype in dir: /Users/ihoneymon/Documents/workspaces/dreaminfra/StudyStruts
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 15.347s
[INFO] Finished at: Wed Oct 12 10:45:18 KST 2011
[INFO] Final Memory: 7M/81M
[INFO] ------------------------------------------------------------------------
HoneyBook:dreaminfra ihoneymon$ cd StudyStruts/
HoneyBook:StudyStruts ihoneymon$ mvn eclipse:eclipse -Dwtpversion=1.5
[INFO] Scanning for projects...
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building Struts 2 Blank Webapp 1.0-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] >>> maven-eclipse-plugin:2.8:eclipse (default-cli) @ StudyStruts >>>
[INFO]
[INFO] <<< maven-eclipse-plugin:2.8:eclipse (default-cli) @ StudyStruts <<<
[INFO]
[INFO] --- maven-eclipse-plugin:2.8:eclipse (default-cli) @ StudyStruts ---
[INFO] Adding support for WTP version 1.5.
[INFO] Using Eclipse Workspace: /Users/ihoneymon/Documents/workspaces/dreaminfra
[WARNING] Workspace defines a VM that does not contain a valid jre/lib/rt.jar: /System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Home
[INFO] no substring wtp server match.
[INFO] Using as WTP server : VMware vFabric tc Server Developer Edition (Runtime) v2.5
[INFO] Adding default classpath container: org.eclipse.jdt.launching.JRE_CONTAINER
[INFO] Not writing settings - defaults suffice
[INFO] Wrote Eclipse project for "StudyStruts" to /Users/ihoneymon/Documents/workspaces/dreaminfra/StudyStruts.
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 2.254s
[INFO] Finished at: Wed Oct 12 10:45:34 KST 2011
[INFO] Final Memory: 6M/81M
[INFO] ------------------------------------------------------------------------
HoneyBook:StudyStruts ihoneymon$
이클립스를 열고, 이 StudyStruts라는 폴더를 import하면 스트럿츠 라이브러리가 설치된 프로젝트를 바로 이용해볼 수 있다. 여기에는 간단한 예제 코드가 포함되어 있다. 이 프로젝트를 서버에 추가하고 실행해보면 다음처럼 나온다.
자! 스트럿츠를 시작해보자.