インストール
- maven-2.0-alpha-1.zip を解凍
- set M2_HOME=d:\dev\maven-2.0-alpha-1 (必須ではないようだ)
- set PATH="%M2_HOME%\bin";%PATH%
ドキュメント
- http://maven.apache.org/maven2/
- 起動には groovyと同じく classworlds 使っている。m2.conf によると ${user.home}/m2 がリポジトリのようだが。。。 m2 install の先は ${user.home}/.m2 だな。
- 1.0と何がちがうのか?
- 1.0との互換をすてた(1.0.2 で打ち止めでバグフックスのみになるようだね)
- Java や他のスクリプトで簡単にプラグインをかくことができる。←すなおに Jelly は失敗だったといえばいいのに。
- 速度とサイズ - Ant, Jelly, Xerces を core でつかっていない。速度はかなり速くなってます。
- 定義されたビルドサイクル - prereqs, preGoals, postGoals がなくなった。
- properties ファイルなし - pom.xml のみ
- maven.xml ファイルなし - plugin を簡単につくれるようになったから(プラグインは plugin.xml が必要)
- jelly なし - 通常は Java や他のスクリプト言語(最初のリリースでは Marmalade(Jelly に似たXMLシンタクス))をサポートする。
- repository レイアウトの向上 - 1.0 とブラウズしやすい構造の2つをサポートする。
- 複数のプロジェクトを簡単に扱える
- 現在の制限事項
- エラー処理がいまいち(いまはStackTraceをだしている。Groovyみたいだ(T_T))
- サイト生成機能がない
- Ant と他のスクリプト言語のサポート
- 1.x のプラグインの利用
動かしてみる
>rem mavenのかわり
>m2 -v
Maven version: 2.0-alpha-1
>m2 -h
usage: maven [options] [goal [goal2 [goal3] ...]]
Options:
-D,--define arg Define a system property
-N,--non-recursive Do not recurse into sub-projects
-U,--update-snapshots Update all snapshots regardless of repository policies
-X,--debug Produce execution debug output
-h,--help Display help information
-o,--offline Work offline
-r,--reactor Execute goals for project found in the reactor
-v,--version Display version information
>rem -g でgoal一覧がでないのは痛いな
>m2 -g
---------------------------------------------------
constituent[0]: file:/d:/dev/maven-2.0-alpha-1/lib/commons-cli-1.0-beta-2.jar
constituent[1]: file:/d:/dev/maven-2.0-alpha-1/lib/marmalade-core-1.0-alpha-2.jar
constituent[2]: file:/d:/dev/maven-2.0-alpha-1/lib/maven-artifact-2.0-SNAPSHOT.jar
constituent[3]: file:/d:/dev/maven-2.0-alpha-1/lib/maven-core-2.0-SNAPSHOT.jar
constituent[4]: file:/d:/dev/maven-2.0-alpha-1/lib/maven-model-2.0-SNAPSHOT.jar
constituent[5]: file:/d:/dev/maven-2.0-alpha-1/lib/maven-monitor-2.0-SNAPSHOT.jar
constituent[6]: file:/d:/dev/maven-2.0-alpha-1/lib/maven-plugin-api-2.0-SNAPSHOT.jar
constituent[7]: file:/d:/dev/maven-2.0-alpha-1/lib/maven-plugin-descriptor-2.0-SNAPSHOT.jar
constituent[8]: file:/d:/dev/maven-2.0-alpha-1/lib/maven-script-marmalade-2.0-SNAPSHOT.jar
constituent[9]: file:/d:/dev/maven-2.0-alpha-1/lib/maven-settings-2.0-SNAPSHOT.jar
constituent[10]: file:/d:/dev/maven-2.0-alpha-1/lib/plexus-container-artifact-1.0-alpha-2.jar
constituent[11]: file:/d:/dev/maven-2.0-alpha-1/lib/plexus-i18n-1.0-beta-3.jar
constituent[12]: file:/d:/dev/maven-2.0-alpha-1/lib/plexus-marmalade-factory-1.0-alpha-2.jar
constituent[13]: file:/d:/dev/maven-2.0-alpha-1/lib/wagon-http-lightweight-1.0-alpha-2.jar
constituent[14]: file:/d:/dev/maven-2.0-alpha-1/lib/wagon-provider-api-1.0-alpha-3-SNAPSHOT.jar
---------------------------------------------------
org.apache.maven.reactor.ReactorException: You must specify at least one goal. Try 'install'.
at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:88)
at org.apache.maven.cli.MavenCli.main(MavenCli.java:230)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:324)
at org.codehaus.classworlds.Launcher.launchEnhanced(Launcher.java:303)
at org.codehaus.classworlds.Launcher.launch(Launcher.java:243)
at org.codehaus.classworlds.Launcher.mainWithExitCode(Launcher.java:416)
at org.codehaus.classworlds.Launcher.main(Launcher.java:363)
>rem maven genapp のかわり
>m2 archetype:create -DgroupId=hoge -DartifactId=hoge -Dpackage=hoge
>cd hoge
>dir /S /B
E:\temp\hoge\pom.xml
E:\temp\hoge\src
E:\temp\hoge\src\main
E:\temp\hoge\src\test
E:\temp\hoge\src\main\java
E:\temp\hoge\src\main\resources
E:\temp\hoge\src\main\java\hoge
E:\temp\hoge\src\main\java\hoge\App.java
E:\temp\hoge\src\test\java
E:\temp\hoge\src\test\resources
E:\temp\hoge\src\test\java\hoge
E:\temp\hoge\src\test\java\hoge\AppTest.java
>rem conf ではなくて resources にかわったようだね
>type pom.xml
<model>
<modelVersion>4.0.0</modelVersion>
<groupId>hoge</groupId>
<artifactId>hoge</artifactId>
<packaging>jar</packaging>
<version>1.0-SNAPSHOT</version>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
</dependencies>
</model>
>rem POMファイルが簡潔になってる
>type src\main\java\hoge\App.java
package hoge;
/**
* Hello world!
*
*/
public class App
{
public static void main( String[] args )
{
System.out.println( "Hello World!" );
}
}
>type src\test\java\hoge\AppTest.java
package hoge;
import junit.framework.Test;
import junit.framework.TestCase;
import junit.framework.TestSuite;
/**
* Unit test for simple App.
*/
public class AppTest
extends TestCase
{
/**
* Create the test case
*
* @param testName name of the test case
*/
public AppTest( String testName )
{
super( testName );
}
/**
* @return the suite of tests being tested
*/
public static Test suite()
{
return new TestSuite( AppTest.class );
}
/**
* Rigourous Test :-)
*/
public void testApp()
{
assertTrue( true );
}
}
>rem コンパイル
>m2 compile
>rem テスト(depend compile)
>m2 test
>rem jarファイルの作成(jarだけだとだめ)
>m2 jar:jar
>dir /S /B *.jar
E:\temp\hoge\target\hoge-1.0-SNAPSHOT.jar
>rem targetフォルダを削除(cleanだけだとだめ)
>m2 clean:clean
>rem パッケージ化(depends test+jar:jar)
>m2 package
warを作ってみる
>m2 archetype:create -DgroupId=hoge -DartifactId=hoge2 -Dpackage=hoge -DarchetypeArtifactId=maven-archetype-webapp
>cd hoge2
>dir /S /B
E:\temp\hoge2\pom.xml
E:\temp\hoge2\src
E:\temp\hoge2\src\main
E:\temp\hoge2\src\test
E:\temp\hoge2\src\main\java
E:\temp\hoge2\src\main\resources
E:\temp\hoge2\src\main\webapp
E:\temp\hoge2\src\main\webapp\index.jsp
E:\temp\hoge2\src\main\webapp\WEB-INF
E:\temp\hoge2\src\main\webapp\WEB-INF\web.xml
E:\temp\hoge2\src\test\java
E:\temp\hoge2\src\test\resources
>type pom.xml
<model>
<modelVersion>4.0.0</modelVersion>
<groupId>hoge</groupId>
<artifactId>hoge2</artifactId>
<packaging>war</packaging>
<version>1.0-SNAPSHOT</version>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<artifactId>maven-war-plugin</artifactId>
<version>1.0-alpha-1</version>
<configuration>
<warName>hoge2</warName>
</configuration>
</plugin>
</plugins>
</build>
</model>
>type src\main\webapp\WEB-INF\web.xml
<!DOCTYPE web-app PUBLIC
"-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
"http://java.sun.com/dtd/web-app_2_3.dtd" >
<web-app>
<display-name>Archetype Created Web Application</display-name>
</web-app>
>rem warを作成(warだけだとだめ)
>m2 war:war
>dir /S /B *.war
E:\temp\hoge2\target\hoge2.war