Mavenお仕着せのディレクトリ構成を受け入れることにより、
コマンド一発でコンパイル・テスト・Jar作成などができる。
すばらしい!

インストール

  1. Javaがインストールされており、環境変数JAVA_HOMEが設定されているのが前提
  2. http://maven.apache.org/ より、maven-2.0.4-bin.zip を取得
  3. 適当なところに展開 (ここでは C:\Maven2 )
  4. パスを通す
    コントロールパネル > システム > システムのプロパティ
     > 詳細設定タブ > 環境変数ボタン
    path.png
     
    MAVEN_HOMEC:\Maven2
    PATH…(既存)…;%MAVEN_HOME%\bin
  5. インストールできたか確認
    C:\>mvn --version
    Maven version: 2.0.4

プロジェクト作成

  1. プロジェクトの作成
    [追記] archetype:create は、Maven 3.0.5 で廃止。代わりに generate を使う
    C:\>mkdir apps
    
    C:\>cd apps
    
    C:\apps>mvn archetype:generate -DgroupId=com.snail.hello -DartifactId=helloMaven
    [INFO] Scanning for projects...
    [INFO] Searching repository for plugin with prefix: 'archetype'.
    [INFO] -------------------------------------------------------------------------
    ---
    [INFO] Building Maven Default Project
    [INFO]    task-segment: [archetype:create] (aggregator-style)
    [INFO] -------------------------------------------------------------------------
    ---
    
    ...
    
    [INFO] Parameter: artifactId, Value: helloMaven
    [INFO] ********************* End of debug info from resources from generated POM
     ***********************
    [INFO] Archetype created in dir: C:\apps\helloMaven
    [INFO] ------------------------------------------------------------------------
    [INFO] BUILD SUCCESSFUL
    [INFO] ------------------------------------------------------------------------
    [INFO] Total time: 9 seconds
    [INFO] Finished at: Wed May 24 00:47:45 JST 2006
    [INFO] Final Memory: 4M/8M
    [INFO] ------------------------------------------------------------------------
  2. 作成したプロジェクト
    C:\apps>tree /F
    フォルダ パスの一覧:  ボリューム IBM_PRELOAD
    ボリューム シリアル番号は 0000403A 40F6:CC2B です
    C:.
    └─helloMaven
        │  pom.xml
        │
        └─src
            ├─main
            │  └─java
            │      └─com
            │          └─snail
            │              └─hello
            │                      App.java
            │
            └─test
                └─java
                    └─com
                        └─snail
                            └─hello
                                    AppTest.java

コンパイル

  1. コンパイル
    C:\apps>cd helloMaven
    
    C:\apps\helloMaven>mvn compile
    [INFO] Scanning for projects...
    [INFO] -------------------------------------------------------------------------
    ---
    [INFO] Building Maven Quick Start Archetype
    [INFO]    task-segment: [compile]
    [INFO] -------------------------------------------------------------------------
    ---
    [INFO] [resources:resources]
    [INFO] Using default encoding to copy filtered resources.
    Downloading: http://repo1.maven.org/maven2/org/codehaus/plexus/plexus-compiler-a
    pi/1.5.2/plexus-compiler-api-1.5.2.pom
    624b downloaded
    Downloading: http://repo1.maven.org/maven2/org/codehaus/plexus/plexus-compiler/1
    .5.2/plexus-compiler-1.5.2.pom
    761b downloaded
    
    ...
    
    [INFO] [compiler:compile]
    Compiling 1 source file to C:\apps\helloMaven\target\classes
    [INFO] ------------------------------------------------------------------------
    [INFO] BUILD SUCCESSFUL
    [INFO] ------------------------------------------------------------------------
    [INFO] Total time: 33 seconds
    [INFO] Finished at: Wed May 24 01:00:44 JST 2006
    [INFO] Final Memory: 2M/8M
    [INFO] ------------------------------------------------------------------------
  2. コンパイル結果
    C:\apps\helloMaven>tree /F
    フォルダ パスの一覧:  ボリューム IBM_PRELOAD
    ボリューム シリアル番号は 0000A97C 40F6:CC2B です
    C:.
    │  pom.xml
    │
    ├─src
    │  ├─main
    │  │  └─java
    │  │      └─com
    │  │          └─snail
    │  │              └─hello
    │  │                      App.java
    │  │
    │  └─test
    │      └─java
    │          └─com
    │              └─snail
    │                  └─hello
    │                          AppTest.java
    │
    └─target
        └─classes
            └─com
                └─snail
                    └─hello
                            App.class

テスト

C:\apps\helloMaven>mvn test
[INFO] Scanning for projects...
[INFO] -------------------------------------------------------------------------
---
[INFO] Building Maven Quick Start Archetype
[INFO]    task-segment: [test]
[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.
Downloading: http://repo1.maven.org/maven2/junit/junit/3.8.1/junit-3.8.1.jar
118K downloaded
[INFO] [compiler:testCompile]
Compiling 1 source file to C:\apps\helloMaven\target\test-classes
Downloading: http://repo1.maven.org/maven2/org/apache/maven/surefire/surefire-bo

...

Downloading: http://repo1.maven.org/maven2/org/apache/maven/surefire/surefire-ju
nit/2.0/surefire-junit-2.0.jar
11K downloaded
[INFO] Surefire report directory: C:\apps\helloMaven\target\surefire-reports

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

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

[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESSFUL
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 28 seconds
[INFO] Finished at: Wed May 24 01:05:16 JST 2006
[INFO] Final Memory: 3M/12M
[INFO] ------------------------------------------------------------------------

配布資産作成

  1. テストと配布資産の作成
    C:\apps\helloMaven>mvn install
    [INFO] Scanning for projects...
    [INFO] -------------------------------------------------------------------------
    ---
    [INFO] Building Maven Quick Start Archetype
    [INFO]    task-segment: [install]
    [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: C:\apps\helloMaven\target\surefire-reports
    
    -------------------------------------------------------
     T E S T S
    -------------------------------------------------------
    Running com.snail.hello.AppTest
    Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.11 sec
    
    Results :
    Tests run: 1, Failures: 0, Errors: 0, Skipped: 0
    
    [INFO] [jar:jar]
    [INFO] Building jar: C:\apps\helloMaven\target\helloMaven-1.0-SNAPSHOT.jar
    [INFO] [install:install]
    [INFO] Installing C:\apps\helloMaven\target\helloMaven-1.0-SNAPSHOT.jar to C:\Do
    cuments and Settings\kagyuu\.m2\repository\com\snail\hello\helloMaven\1.0-SNAPSH
    OT\helloMaven-1.0-SNAPSHOT.jar
    [INFO] ------------------------------------------------------------------------
    [INFO] BUILD SUCCESSFUL
    [INFO] ------------------------------------------------------------------------
    [INFO] Total time: 7 seconds
    [INFO] Finished at: Wed May 24 01:13:00 JST 2006
    [INFO] Final Memory: 3M/7M
    [INFO] ------------------------------------------------------------------------
  2. 配布資産の在処
    C:\apps\helloMaven>tree /F
    フォルダ パスの一覧:  ボリューム IBM_PRELOAD
    ボリューム シリアル番号は 0000A0B6 40F6:CC2B です
    C:.
    │  pom.xml
    │
    ├─src
    │  ├─main
    │  │  └─java
    │  │      └─com
    │  │          └─snail
    │  │              └─hello
    │  │                      App.java
    │  │
    │  └─test
    │      └─java
    │          └─com
    │              └─snail
    │                  └─hello
    │                          AppTest.java
    │
    └─target
        │  exported-pom.xml
        │  helloMaven-1.0-SNAPSHOT.jar
        │
        ├─classes
        │  └─com
        │      └─snail
        │          └─hello
        │                  App.class
        │
        ├─surefire-reports
        │      com.snail.hello.AppTest.txt
        │      TEST-com.snail.hello.AppTest.xml
        │
        └─test-classes
            └─com
                └─snail
                    └─hello
                            AppTest.class

プロジェクト公開サイトの作成

C:\apps\helloMaven>mvn site

...

Downloading: http://repo1.maven.org/maven2/org/apache/maven/skins/maven-default-
skin/1.0/maven-default-skin-1.0.jar
7K downloaded
[INFO] Generate "Continuous Integration" report.
[ERROR] VM #displayTree: error : too few arguments to macro. Wanted 2 got 0
[ERROR] VM #menuItem: error : too few arguments to macro. Wanted 1 got 0
[INFO] Generate "Dependencies" report.
[INFO] Generate "Issue Tracking" report.
[INFO] Generate "Project License" report.
[INFO] Generate "Mailing Lists" report.
[INFO] Generate "About" report.
[INFO] Generate "Project Summary" report.
[INFO] Generate "Source Repository" report.
[INFO] Generate "Project Team" report.
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESSFUL
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 2 minutes 24 seconds
[INFO] Finished at: Wed May 24 01:19:30 JST 2006
[INFO] Final Memory: 10M/21M
[INFO] ------------------------------------------------------------------------
 
C:\apps\helloMaven>tree /F
フォルダ パスの一覧:  ボリューム IBM_PRELOAD
ボリューム シリアル番号は 0000A0DD 40F6:CC2B です
C:.
│  pom.xml
│
├─src
│  ├─main
│  │  └─java
│  │      └─com
│  │          └─snail
│  │              └─hello
│  │                      App.java
│  │
│  └─test
│      └─java
│          └─com
│              └─snail
│                  └─hello
│                          AppTest.java
│
└─target
    │  exported-pom.xml
    │  helloMaven-1.0-SNAPSHOT.jar
    │
    ├─classes
    │  └─com
    │      └─snail
    │          └─hello
    │                  App.class
    │
    ├─site
    │  │  dependencies.html
    │  │  index.html
    │  │  integration.html
    │  │  issue-tracking.html
    │  │  license.html
    │  │  mail-lists.html
    │  │  project-info.html
    │  │  project-summary.html
    │  │  source-repository.html
    │  │  team-list.html
    │  │
    │  ├─css
    │  │      maven-base.css
    │  │      maven-theme.css
    │  │      print.css
    │  │
    │  └─images
    │      │  collapsed.gif
    │      │  expanded.gif
    │      │  external.png
    │      │  icon_error_sml.gif
    │      │  icon_info_sml.gif
    │      │  icon_success_sml.gif
    │      │  icon_warning_sml.gif
    │      │  newwindow.png
    │      │
    │      └─logos
    │              maven-feather.png
    │
    ├─surefire-reports
    │      com.snail.hello.AppTest.txt
    │      TEST-com.snail.hello.AppTest.xml
    │
    └─test-classes
        └─com
            └─snail
                └─hello
                        AppTest.class

資産削除

C:\apps\helloMaven>mvn clean

Java Maven


添付ファイル: filepath.png 969件 [詳細]

トップ   編集 凍結 差分 バックアップ 添付 複製 名前変更 リロード   新規 一覧 単語検索 最終更新   ヘルプ   最終更新のRSS   sitemap
Last-modified: 2006-05-24 (水) 01:50:18 (3853d)
ISBN10
ISBN13
9784061426061