倭マン's BLOG

くだらない日々の日記書いてます。 たまにプログラミング関連の記事書いてます。 書いてます。

Archetype -- generate ゴール (1):対話的にプロジェクトを作成する

最近あまり使っていなかったので更新に疎くなっていましたが、Archetype プラグインの「generate ゴール」がそれなりに使いやすくなっているようなので、使い方を見てみましょう。 といっても、以前の記事と内容はあまり変わりませんが*1

プロジェクトの作成方法は次の2種類があります:

  • 対話的にプロジェクトを作成する
  • パラメータを指定してプロジェクトを作成する

今回は「対話的にプロジェクトを作成する」方法を見ていきます。 「パラメータを指定してプロジェクトを作成する」は次回に。

対話的にプロジェクトを作成する

この方法は、単純な Maven2 プロジェクトを作成するのに使います。 流れは以下のようになります:

  1. コマンドを実行する
  2. archetype を選択する
  3. プロジェクトのパラメータを設定する

★コマンドを実行する★
対話的に Maven2 プロジェクトを生成するには、まず以下のコマンドを実行します:

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
[INFO] No goals needed for project - skipping
[INFO] Setting property: classpath.resource.loader.class => 'org.codehaus.plexus.velocity.ContextClassLoaderResourceLoader'.
[INFO] Setting property: velocimacro.messages.on => 'false'.
[INFO] Setting property: resource.loader => 'classpath'.
[INFO] Setting property: resource.manager.logwhenfound => 'false'.
[INFO] [archetype:generate]
[INFO] Generating project in Interactive mode

★archetype を選択する★
上記のメッセージに引き続き、「archetype の選択」を促すメッセージが表示されるので、生成したい archetype の番号を入力します:

[INFO] No archetype defined. Using maven-archetype-quickstart (org.apache.maven.archetypes:maven-archetype-quickstart:1.0)
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)
3: internal -> appfuse-basic-struts (AppFuse archetype for creating a web application with Hibernate, Spring and Struts 2)
4: internal -> appfuse-basic-tapestry (AppFuse archetype for creating a web application with Hibernate, Spring and Tapestry 4)
5: internal -> appfuse-core (AppFuse archetype for creating a jar application with Hibernate and Spring and XFire)
6: internal -> appfuse-modular-jsf (AppFuse archetype for creating a modular application with Hibernate, Spring and JSF)
7: internal -> appfuse-modular-spring (AppFuse archetype for creating a modular application with Hibernate, Spring and Spring MVC)
8: internal -> appfuse-modular-struts (AppFuse archetype for creating a modular application with Hibernate, Spring and Struts 2)
9: internal -> appfuse-modular-tapestry (AppFuse archetype for creating a modular application with Hibernate, Spring and Tapestry 4)
10: internal -> maven-archetype-j2ee-simple (A simple J2EE Java application)
11: internal -> maven-archetype-marmalade-mojo (A Maven plugin development project using marmalade)
12: internal -> maven-archetype-mojo (A Maven Java plugin development project)
13: internal -> maven-archetype-portlet (A simple portlet application)
14: internal -> maven-archetype-profiles ()
15: internal -> maven-archetype-quickstart ()
16: internal -> maven-archetype-site-simple (A simple site generation project)
17: internal -> maven-archetype-site (A more complex site project)
18: internal -> maven-archetype-webapp (A simple Java web application)
19: internal -> jini-service-archetype (Archetype for Jini service project creation)
20: internal -> softeu-archetype-seam (JSF+Facelets+Seam Archetype)
21: internal -> softeu-archetype-seam-simple (JSF+Facelets+Seam (no persistence) Archetype)
22: internal -> softeu-archetype-jsf (JSF+Facelets Archetype)
23: internal -> jpa-maven-archetype (JPA application)
24: internal -> spring-osgi-bundle-archetype (Spring-OSGi archetype)
25: internal -> confluence-plugin-archetype (Atlassian Confluence plugin archetype)
26: internal -> jira-plugin-archetype (Atlassian JIRA plugin archetype)
27: internal -> maven-archetype-har (Hibernate Archive)
28: internal -> maven-archetype-sar (JBoss Service Archive)
29: internal -> wicket-archetype-quickstart (A simple Apache Wicket project)
30: internal -> scala-archetype-simple (A simple scala project)
31: internal -> lift-archetype-blank (A blank/empty liftweb project)
32: internal -> lift-archetype-basic (The basic (liftweb) project)
33: internal -> cocoon-22-archetype-block-plain (http://cocoon.apache.org/2.2/maven-plugins/)
34: internal -> cocoon-22-archetype-block (http://cocoon.apache.org/2.2/maven-plugins/)
35: internal -> cocoon-22-archetype-webapp (http://cocoon.apache.org/2.2/maven-plugins/)
36: internal -> myfaces-archetype-helloworld (A simple archetype using MyFaces)
37: internal -> myfaces-archetype-helloworld-facelets (A simple archetype using MyFaces and facelets)
38: internal -> myfaces-archetype-trinidad (A simple archetype using Myfaces and Trinidad)
39: internal -> myfaces-archetype-jsfcomponents (A simple archetype for create custom JSF components using MyFaces)
40: internal -> gmaven-archetype-basic (Groovy basic archetype)
41: internal -> gmaven-archetype-mojo (Groovy mojo archetype)
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[Enter]

ここでは「15 (maven-archetype-quickstart)」を選択しています。

デフォルト値は 「15」なので、番号を入力せずに [Enter] を入力すると、「maven-archetype-quickstart」が指定されます。

★プロジェクトのパラメータを設定する★
次にプロジェクトのパラメータを入力するように促されます。 必要なパラメータは

  • groupId : 開発グループの ID
  • artifactId : 成果物の ID
  • version : 成果物のバージョン
  • package : (ルート)パッケージの名前

の4つです。ここではパラメータの値として以下のものを指定することにします:

パラメータ名
groupId org.sample
artifactId sample
version デフォルト値 (1.0-SNAPSHOT)
package デフォルト値(groupId と同じ)

これらの値を設定するには、以下の太字の様に入力します(灰色の部分は指定した値によって表示が異なります):

Define value for groupId: : org.sample[Enter]
Define value for artifactId: : sample[Enter]
Define value for version: 1.0-SNAPSHOT: : [Enter]
Define value for package: org.sample: : [Enter]
Confirm properties configuration:
groupId: org.sample
artifactId: sample
version: 1.0-SNAPSHOT
package: org.sample
Y: : y[Enter]
[INFO] ----------------------------------------------------------------------------
[INFO] Using following parameters for creating OldArchetype: maven-archetype-quickstart:RELEASE
[INFO] ----------------------------------------------------------------------------
[INFO] Parameter: groupId, Value: org.sample
[INFO] Parameter: packageName, Value: org.sample
[INFO] Parameter: package, Value: org.sample
[INFO] Parameter: artifactId, Value: sample
[INFO] Parameter: basedir, Value: C:\test
[INFO] Parameter: version, Value: 1.0-SNAPSHOT
[INFO] ********************* End of debug info from resources from generated POM ***********************
[INFO] OldArchetype created in dir: C:\test\sample
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESSFUL
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 1 minute
[INFO] Finished at: Sun Apr 26 04:07:48 JST 2009
[INFO] Final Memory: 8M/15M
[INFO] ------------------------------------------------------------------------

以上で終わりです。

Apache Maven 2.0入門 Java・オープンソース・ビルドツール

Apache Maven 2.0入門 Java・オープンソース・ビルドツール

*1:以前の記事では、コマンド「mvn archetype:create」によって対話的にプロジェクトを作成すると書いてましたがこれは間違い。