サンプル集 |
■VC ■C# ■Java ■BorlandC ■LinuxC ■MS-DOS ■bash ■Excel VBA ■VBScript ■PHP ■HTML ■perl ■iPhone ■Android ■Lua ■other |
Linuxコマンド |
用語集 |
debian メモ |
apache2 メモ |
MySQL メモ |
Oracle メモ |
HOME |
Mavenを使ってみます。
◆環境OS | Windows 7 Professional Service Pack 1 (64bit) |
---|
Mavenはプロジェクト定義ファイル(POM:Project Object Model)に従い処理を行うようです。
Mavenのバージョンを確認します。
> mvn -v
Apache Maven 3.1.1 (0728685237757ffbf44136acec0402957f723d9a; 2013-09-1
8 00:22:22+0900)
Maven home: C:\Program Files\Apache Software Foundation\apache-maven-3.
1.1\bin\..
Java version: 1.6.0_45, vendor: Sun Microsystems Inc.
Java home: C:\Program Files\Java\jdk1.6.0_45\jre
Default locale: ja_JP, platform encoding: MS932
OS name: "windows 7", version: "6.1", arch: "amd64", family: "windows"
Apache Maven 3.1.1 (0728685237757ffbf44136acec0402957f723d9a; 2013-09-1
8 00:22:22+0900)
Maven home: C:\Program Files\Apache Software Foundation\apache-maven-3.
1.1\bin\..
Java version: 1.6.0_45, vendor: Sun Microsystems Inc.
Java home: C:\Program Files\Java\jdk1.6.0_45\jre
Default locale: ja_JP, platform encoding: MS932
OS name: "windows 7", version: "6.1", arch: "amd64", family: "windows"
サンプルプロジェクトを作ってみます。 archetypeArtifactId に maven-archetype-webapp を指定しWebアプリケーション用ひな形の作成を指示します。
> mvn archetype:create -DgroupId=jp.test -DartifactId=mvn-test -Darchet
ypeArtifactId=maven-archetype-webapp
[INFO] Scanning for projects...
Downloading: http://repo.maven.apache.org/maven2/org/apache/maven/plugi
ns/maven-deploy-plugin/2.7/maven-deploy-plugin-2.7.pom
Downloaded: http://repo.maven.apache.org/maven2/org/apache/maven/plugin
s/maven-deploy-plugin/2.7/maven-deploy-plugin-2.7.pom (6 KB at 0.7
KB/sec)
Downloading: http://repo.maven.apache.org/maven2/org/apache/maven/plugi
ns/maven-deploy-plugin/2.7/maven-deploy-plugin-2.7.jar
:
[INFO]
[INFO] ----------------------------------------------------------------
[INFO] Building Maven Stub Project (No POM) 1
[INFO] ----------------------------------------------------------------
[INFO]
[INFO] --- maven-archetype-plugin:2.2:create (default-cli) @ standalone
-pom ---
Downloading: http://repo.maven.apache.org/maven2/org/apache/maven/arche
type/archetype-catalog/2.2/archetype-catalog-2.2.pom
Downloaded: http://repo.maven.apache.org/maven2/org/apache/maven/archet
ype/archetype-catalog/2.2/archetype-catalog-2.2.pom (2 KB at 4.5 KB
/sec)
Downloading: http://repo.maven.apache.org/maven2/org/apache/maven/arche
type/archetype-models/2.2/archetype-models-2.2.pom
:
[WARNING] This goal is deprecated. Please use mvn archetype:generate in
stead
[INFO] Defaulting package to group ID: jp.test
Downloading: http://repo.maven.apache.org/maven2/org/apache/maven/arche
types/maven-archetype-webapp/maven-metadata.xml
Downloaded: http://repo.maven.apache.org/maven2/org/apache/maven/archet
ypes/maven-archetype-webapp/maven-metadata.xml (498 B at 0.9 KB/sec
)
:
[INFO] ----------------------------------------------------------------
[INFO] Using following parameters for creating project from Old (1.x) A
rchetype: maven-archetype-webapp:RELEASE
[INFO] ----------------------------------------------------------------
[INFO] Parameter: groupId, Value: jp.test
[INFO] Parameter: packageName, Value: jp.test
[INFO] Parameter: package, Value: jp.test
[INFO] Parameter: artifactId, Value: mvn-test
[INFO] Parameter: basedir, Value: C:
[INFO] Parameter: version, Value: 1.0-SNAPSHOT
[INFO] project created from Old (1.x) Archetype in dir: C:\mvn-test
[INFO] ----------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ----------------------------------------------------------------
[INFO] Total time: 17.706s
[INFO] Finished at: Wed Aug 06 11:50:18 JST 2014
[INFO] Final Memory: 9M/77M
[INFO] ----------------------------------------------------------------
ypeArtifactId=maven-archetype-webapp
[INFO] Scanning for projects...
Downloading: http://repo.maven.apache.org/maven2/org/apache/maven/plugi
ns/maven-deploy-plugin/2.7/maven-deploy-plugin-2.7.pom
Downloaded: http://repo.maven.apache.org/maven2/org/apache/maven/plugin
s/maven-deploy-plugin/2.7/maven-deploy-plugin-2.7.pom (6 KB at 0.7
KB/sec)
Downloading: http://repo.maven.apache.org/maven2/org/apache/maven/plugi
ns/maven-deploy-plugin/2.7/maven-deploy-plugin-2.7.jar
:
[INFO]
[INFO] ----------------------------------------------------------------
[INFO] Building Maven Stub Project (No POM) 1
[INFO] ----------------------------------------------------------------
[INFO]
[INFO] --- maven-archetype-plugin:2.2:create (default-cli) @ standalone
-pom ---
Downloading: http://repo.maven.apache.org/maven2/org/apache/maven/arche
type/archetype-catalog/2.2/archetype-catalog-2.2.pom
Downloaded: http://repo.maven.apache.org/maven2/org/apache/maven/archet
ype/archetype-catalog/2.2/archetype-catalog-2.2.pom (2 KB at 4.5 KB
/sec)
Downloading: http://repo.maven.apache.org/maven2/org/apache/maven/arche
type/archetype-models/2.2/archetype-models-2.2.pom
:
[WARNING] This goal is deprecated. Please use mvn archetype:generate in
stead
[INFO] Defaulting package to group ID: jp.test
Downloading: http://repo.maven.apache.org/maven2/org/apache/maven/arche
types/maven-archetype-webapp/maven-metadata.xml
Downloaded: http://repo.maven.apache.org/maven2/org/apache/maven/archet
ypes/maven-archetype-webapp/maven-metadata.xml (498 B at 0.9 KB/sec
)
:
[INFO] ----------------------------------------------------------------
[INFO] Using following parameters for creating project from Old (1.x) A
rchetype: maven-archetype-webapp:RELEASE
[INFO] ----------------------------------------------------------------
[INFO] Parameter: groupId, Value: jp.test
[INFO] Parameter: packageName, Value: jp.test
[INFO] Parameter: package, Value: jp.test
[INFO] Parameter: artifactId, Value: mvn-test
[INFO] Parameter: basedir, Value: C:
[INFO] Parameter: version, Value: 1.0-SNAPSHOT
[INFO] project created from Old (1.x) Archetype in dir: C:\mvn-test
[INFO] ----------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ----------------------------------------------------------------
[INFO] Total time: 17.706s
[INFO] Finished at: Wed Aug 06 11:50:18 JST 2014
[INFO] Final Memory: 9M/77M
[INFO] ----------------------------------------------------------------
Downloading がたくさん表示されました。 Web上にあるリモート・リポジトリからローカルPCのローカル・リポジトリに必要なファイルなどがダウンロードされました。
ローカル・リポジトリは通常はユーザーのホームディレクトリの /.m2/repository です。
処理が終わると、mvn-testというフォルダが作成されます。 mvn-test へ移動し、mvn packeageを実行します。
> cd mvn-test
mvn-test> mvn package
[INFO] Scanning for projects...
[INFO]
[INFO] ----------------------------------------------------------------
[INFO] Building mvn-test Maven Webapp 1.0-SNAPSHOT
[INFO] ----------------------------------------------------------------
[INFO]
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ m
vn-test ---
[WARNING] Using platform encoding (MS932 actually) to copy filtered res
ources, i.e. build is platform dependent!
[INFO] Copying 0 resource
[INFO]
[INFO] --- maven-compiler-plugin:2.5.1:compile (default-compile) @ mvn-
test ---
[INFO] No sources to compile
[INFO]
[INFO] --- maven-resources-plugin:2.6:testResources (default-testResour
ces) @ mvn-test ---
[WARNING] Using platform encoding (MS932 actually) to copy filtered res
ources, i.e. build is platform dependent!
[INFO] skip non existing resourceDirectory C:\mvn-test\src\test\resourc
es
[INFO]
[INFO] --- maven-compiler-plugin:2.5.1:testCompile (default-testCompile
) @ mvn-test ---
[INFO] No sources to compile
[INFO]
[INFO] --- maven-surefire-plugin:2.12.4:test (default-test) @ mvn-test
---
[INFO] No tests to run.
[INFO]
[INFO] --- maven-war-plugin:2.2:war (default-war) @ mvn-test ---
[INFO] Packaging webapp
[INFO] Assembling webapp [mvn-test] in [C:\mvn-test\target\mvn-test]
[INFO] Processing war project
[INFO] Copying webapp resources [C:\mvn-test\src\main\webapp]
[INFO] Webapp assembled in [78 msecs]
[INFO] Building war: C:\mvn-test\target\mvn-test.war
[INFO] WEB-INF\web.xml already added, skipping
[INFO] ----------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ----------------------------------------------------------------
[INFO] Total time: 2.340s
[INFO] Finished at: Wed Aug 06 11:53:48 JST 2014
[INFO] Final Memory: 7M/107M
[INFO] ----------------------------------------------------------------
mvn-test> mvn package
[INFO] Scanning for projects...
[INFO]
[INFO] ----------------------------------------------------------------
[INFO] Building mvn-test Maven Webapp 1.0-SNAPSHOT
[INFO] ----------------------------------------------------------------
[INFO]
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ m
vn-test ---
[WARNING] Using platform encoding (MS932 actually) to copy filtered res
ources, i.e. build is platform dependent!
[INFO] Copying 0 resource
[INFO]
[INFO] --- maven-compiler-plugin:2.5.1:compile (default-compile) @ mvn-
test ---
[INFO] No sources to compile
[INFO]
[INFO] --- maven-resources-plugin:2.6:testResources (default-testResour
ces) @ mvn-test ---
[WARNING] Using platform encoding (MS932 actually) to copy filtered res
ources, i.e. build is platform dependent!
[INFO] skip non existing resourceDirectory C:\mvn-test\src\test\resourc
es
[INFO]
[INFO] --- maven-compiler-plugin:2.5.1:testCompile (default-testCompile
) @ mvn-test ---
[INFO] No sources to compile
[INFO]
[INFO] --- maven-surefire-plugin:2.12.4:test (default-test) @ mvn-test
---
[INFO] No tests to run.
[INFO]
[INFO] --- maven-war-plugin:2.2:war (default-war) @ mvn-test ---
[INFO] Packaging webapp
[INFO] Assembling webapp [mvn-test] in [C:\mvn-test\target\mvn-test]
[INFO] Processing war project
[INFO] Copying webapp resources [C:\mvn-test\src\main\webapp]
[INFO] Webapp assembled in [78 msecs]
[INFO] Building war: C:\mvn-test\target\mvn-test.war
[INFO] WEB-INF\web.xml already added, skipping
[INFO] ----------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ----------------------------------------------------------------
[INFO] Total time: 2.340s
[INFO] Finished at: Wed Aug 06 11:53:48 JST 2014
[INFO] Final Memory: 7M/107M
[INFO] ----------------------------------------------------------------
フォルダの状態をみてみます。
> tree /f mvn-test
C:\MVN-TEST
│ pom.xml
├─src
│ └─main
│ ├─resources
│ └─webapp
│ │ index.jsp
│ └─WEB-INF
│ web.xml
└─target
│ mvn-test.war
├─classes
├─maven-archiver
│ pom.properties
└─mvn-test
│ index.jsp
├─META-INF
└─WEB-INF
│ web.xml
└─classes
C:\MVN-TEST
│ pom.xml
├─src
│ └─main
│ ├─resources
│ └─webapp
│ │ index.jsp
│ └─WEB-INF
│ web.xml
└─target
│ mvn-test.war
├─classes
├─maven-archiver
│ pom.properties
└─mvn-test
│ index.jsp
├─META-INF
└─WEB-INF
│ web.xml
└─classes
mvn-test/target フォルダに mvn-test.war ファイルが作成されました。
POMファイルの内容は以下の通りでした。
pom.xml | ||
|
groupId | プロジェクトグループのID |
artifactId | プロジェクトのID |
packaging | 作成する成果物の種類(JAR,WAR,EARなど) |
version | プロジェクトのバージョン |
name | プロジェクトの表示名 |
url | プロジェクトのサイトURL |
dependencies | プロジェクトが依存するライブラリの情報 |
Dependencyの要素
groupId | 依存するライブラリのグループのID |
artifactId | 依存するライブラリのID |
version | 依存するライブラリのバージョン |
scope | 依存するライブラリがいつクラスパスに追加されるかを指定 |
Dependencyのscopeに指定する値
compile | 常にクラスパスに追加される。 scopeの指定を省略した場合、compileが適用される。 |
provided | ライブラリがJDKやコンテナによって提供される場合に指定。コンパイル時のみクラスパスに追加される。 |
runtime | 実行時のみに必要な場合に指定。実行時にクラスパスに追加される。 |
test | テスト時のみ必要な場合に指定。テストのコンパイルと実行時にクラスパスに追加される。 |
system | 明示的にクラスパスに追加する場合に指定。このスコープのライブラリは常に有効とみなされ、リポジトリの検索は行われない。 |
Copyright (C) 2014 - 2015 ymlib.com