Top / Maven2

MavenはApacheが開発しているプロダクト管理ツール(?)です。Antの用にビルドしたり、プロジェクト用のサイトを作成したり、JavaDoc?を作成したり、JUnitを実行したりできる何でもありツールですね。

Install

http://maven.apache.org/download.html よりダウンロードし、適当なところに解凍しておけば完了です。パスを通しておけば完璧です。

基本

プロジェクトを作る

まずはプロジェクトの作り方です。

mvn archetype:create -DgroupId=nu.mine.kino.mavensample -DartifactId=kino-app

で、以下のプロジェクト構成ができあがります。

bash-3.2$ pwd
/cygdrive/t/workspace3.2
bash-3.2$ mvn archetype:create -DgroupId=nu.mine.kino.mavensample -DartifactId=
kino-app
[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] 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] **************************************************************
[INFO] Starting Jakarta Velocity v1.4
[INFO] RuntimeInstance initializing.
[INFO] Default Properties File: org\apache\velocity\runtime\defaults\velocity.pr
operties
[INFO] Default ResourceManager initializing. (class org.apache.velocity.runtime.
resource.ResourceManagerImpl)
[INFO] Resource Loader Instantiated: org.codehaus.plexus.velocity.ContextClassLo
aderResourceLoader
[INFO] ClasspathResourceLoader : initialization starting.
[INFO] ClasspathResourceLoader : initialization complete.
[INFO] ResourceCache : initialized. (class org.apache.velocity.runtime.resource.
ResourceCacheImpl)
[INFO] Default ResourceManager initialization complete.
[INFO] Loaded System Directive: org.apache.velocity.runtime.directive.Literal
[INFO] Loaded System Directive: org.apache.velocity.runtime.directive.Macro
[INFO] Loaded System Directive: org.apache.velocity.runtime.directive.Parse
[INFO] Loaded System Directive: org.apache.velocity.runtime.directive.Include
[INFO] Loaded System Directive: org.apache.velocity.runtime.directive.Foreach
[INFO] Created: 20 parsers.
[INFO] Velocimacro : initialization starting.
[INFO] Velocimacro : adding VMs from VM library template : VM_global_library.vm
[ERROR] ResourceManager : unable to find resource 'VM_global_library.vm' in any
resource loader.
[INFO] Velocimacro : error using  VM library template VM_global_library.vm : org
.apache.velocity.exception.ResourceNotFoundException: Unable to find resource 'V
M_global_library.vm'
[INFO] Velocimacro :  VM library template macro registration complete.
[INFO] Velocimacro : allowInline = true : VMs can be defined inline in templates

[INFO] Velocimacro : allowInlineToOverride = false : VMs defined inline may NOT
replace previous VM definitions
[INFO] Velocimacro : allowInlineLocal = false : VMs defined inline will be  glob
al in scope if allowed.
[INFO] Velocimacro : initialization complete.
[INFO] Velocity successfully started.
[INFO] [archetype:create]
[INFO] Defaulting package to group ID: nu.mine.kino.mavensample
[INFO] artifact org.apache.maven.archetypes:maven-archetype-quickstart: checking
 for updates from central
[INFO] -------------------------------------------------------------------------
---
[INFO] Using following parameters for creating Archetype: maven-archetype-quicks
tart:RELEASE
[INFO] -------------------------------------------------------------------------
---
[INFO] Parameter: groupId, Value: nu.mine.kino.mavensample
[INFO] Parameter: packageName, Value: nu.mine.kino.mavensample
[INFO] Parameter: basedir, Value: T:\workspace3.2
[INFO] Parameter: package, Value: nu.mine.kino.mavensample
[INFO] Parameter: version, Value: 1.0-SNAPSHOT
[INFO] Parameter: artifactId, Value: kino-app
[INFO] ********************* End of debug info from resources from generated POM
 ***********************
[INFO] Archetype created in dir: T:\workspace3.2\kino-app
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESSFUL
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 6 seconds
[INFO] Finished at: Fri Jun 22 00:02:38 JST 2007
[INFO] Final Memory: 4M/8M
[INFO] ------------------------------------------------------------------------
bash-3.2$ ls -lrt kino-app
total 1
-rwx------+ 1 m-kino mkgroup 653 Jun 22 00:02 pom.xml <-プロジェクトの設定ファイル
drwx------+ 4 m-kino mkgroup   0 Jun 22 00:02 src
bash-3.2$

コンパイルする

コンパイルするにはプロジェクトのディレクトリに移動して、

bash-3.2$ mvn compile

でOK.

bash-3.2$ ls -lrt kino-app
total 1
-rwx------+ 1 m-kino mkgroup 653 Jun 22 00:02 pom.xml
drwx------+ 4 m-kino mkgroup   0 Jun 22 00:02 src
bash-3.2$ cd kino-app/
bash-3.2$ pwd
/cygdrive/t/workspace3.2/kino-app
bash-3.2$ mvn compile
[INFO] Scanning for projects...
[INFO] -------------------------------------------------------------------------
---
[INFO] Building kino-app
[INFO]    task-segment: [compile]
[INFO] -------------------------------------------------------------------------
---
[INFO] artifact org.apache.maven.plugins:maven-resources-plugin: checking for up
dates from central
Downloading: http://repo1.maven.org/maven2/org/apache/maven/plugins/maven-resour
ces-plugin/2.2/maven-resources-plugin-2.2.pom
1K downloaded
Downloading: http://repo1.maven.org/maven2/org/apache/maven/plugins/maven-plugin
s/1/maven-plugins-1.pom
3K downloaded
Downloading: http://repo1.maven.org/maven2/org/apache/maven/plugins/maven-resour
ces-plugin/2.2/maven-resources-plugin-2.2.jar
13K downloaded
[INFO] artifact org.apache.maven.plugins:maven-compiler-plugin: checking for upd
ates from central
Downloading: http://repo1.maven.org/maven2/org/apache/maven/plugins/maven-compil
er-plugin/2.0.2/maven-compiler-plugin-2.0.2.pom
2K downloaded
Downloading: http://repo1.maven.org/maven2/org/apache/maven/plugins/maven-plugin
s/8/maven-plugins-8.pom
5K downloaded
Downloading: http://repo1.maven.org/maven2/org/apache/maven/maven-parent/5/maven
-parent-5.pom
14K downloaded
Downloading: http://repo1.maven.org/maven2/org/apache/apache/3/apache-3.pom
3K downloaded
Downloading: http://repo1.maven.org/maven2/org/apache/maven/plugins/maven-compil
er-plugin/2.0.2/maven-compiler-plugin-2.0.2.jar
17K downloaded
[INFO] [resources:resources]
[INFO] Using default encoding to copy filtered resources.
Downloading: http://repo1.maven.org/maven2/org/codehaus/plexus/plexus-compiler-m
anager/1.5.3/plexus-compiler-manager-1.5.3.pom
634b downloaded
Downloading: http://repo1.maven.org/maven2/org/codehaus/plexus/plexus-compiler/1
.5.3/plexus-compiler-1.5.3.pom
1K downloaded
Downloading: http://repo1.maven.org/maven2/org/codehaus/plexus/plexus-components
/1.1.6/plexus-components-1.1.6.pom
1K downloaded
Downloading: http://repo1.maven.org/maven2/org/codehaus/plexus/plexus/1.0.8/plex
us-1.0.8.pom
7K downloaded
Downloading: http://repo1.maven.org/maven2/org/codehaus/plexus/plexus-compiler-a
pi/1.5.3/plexus-compiler-api-1.5.3.pom
624b downloaded
Downloading: http://repo1.maven.org/maven2/org/codehaus/plexus/plexus-compiler-j
avac/1.5.3/plexus-compiler-javac-1.5.3.pom
797b downloaded
Downloading: http://repo1.maven.org/maven2/org/codehaus/plexus/plexus-compilers/
1.5.3/plexus-compilers-1.5.3.pom
7K downloaded
Downloading: http://repo1.maven.org/maven2/org/codehaus/plexus/plexus-utils/1.0.
5/plexus-utils-1.0.5.pom
918b downloaded
Downloading: http://repo1.maven.org/maven2/org/codehaus/plexus/plexus-compiler-a
pi/1.5.3/plexus-compiler-api-1.5.3.jar
19K downloaded
Downloading: http://repo1.maven.org/maven2/org/codehaus/plexus/plexus-compiler-j
avac/1.5.3/plexus-compiler-javac-1.5.3.jar
13K downloaded
Downloading: http://repo1.maven.org/maven2/org/codehaus/plexus/plexus-utils/1.0.
4/plexus-utils-1.0.4.jar
159K downloaded
Downloading: http://repo1.maven.org/maven2/org/codehaus/plexus/plexus-compiler-m
anager/1.5.3/plexus-compiler-manager-1.5.3.jar
5K downloaded
[INFO] [compiler:compile]
[INFO] Compiling 1 source file to t:\workspace3.2\kino-app\target\classes
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESSFUL
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 24 seconds
[INFO] Finished at: Fri Jun 22 00:07:34 JST 2007
[INFO] Final Memory: 2M/8M
[INFO] ------------------------------------------------------------------------
bash-3.2$

Mavenは

mvn compile

など、Antでいうタスクのようなモノを引数に起動すると、そのタスクに必要なライブラリをネット上のリポジトリから勝手にダウンロードしてきてキャッシュし、それを使用します。上の例だと

Downloading: http://repo1.maven.org/maven2/org/codehaus/plexus/plexus-compiler-m
anager/1.5.3/plexus-compiler-manager-1.5.3.jar

とかやってるわけですね。

コンパイルが完了すると target というディレクトリの中にコンパイルされてクラスファイルが入ってました。

コンテンツ一覧

関連リンク


FrontPage
現在のアクセス:10498


トップ   編集 凍結 差分 バックアップ 添付 複製 名前変更 リロード   新規 一覧 単語検索 最終更新   ヘルプ   最終更新のRSS
Last-modified: 2016-07-20 (水) 07:48:53 (1217d)