Maven2 に入門してみる
- 環境導入
- プロジェクトの雛形作成
- コンパイル
- テスト実行
- Javadoc 作成
- サイト作成
- ローカルリポジトリへのインストール(してない)
こんな感じで進めていきます。
1. 環境導入
aptitude install maven2
2. プロジェクトの雛形作成
mvn archetype:create -DgroupId=jp.dip.oyasirazu.morphologicalanalysis -DartifactId=MorphologicalAnalysis
...(snip)
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESSFUL
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 11 seconds
[INFO] Finished at: Sat Jan 05 03:59:56 JST 2013
[INFO] Final Memory: 16M/151M
[INFO] ------------------------------------------------------------------------
...なんかゴリゴリ出力されていますね。 jar のダウンロードもされているようだ...(初回だけらしい)。 こんな風な構成になっていれば成功らしい。
mikoto@mndebian:~/projects/maven$ tree
.
└── MorphologicalAnalysis
├── pom.xml
└── src
├── main
│ └── java
│ └── jp
│ └── dip
│ └── oyasirazu
│ └── morphologicalanalysis
│ └── App.java
└── test
└── java
└── jp
└── dip
└── oyasirazu
└── morphologicalanalysis
└── AppTest.java
14 directories, 3 files
OK. とりあえず雛形の状態で Git に登録する。
git init
git add --all
git commit -m 'Initial commit'
3. 雛形プロジェクトのコンパイル
mvn compile
[INFO] Scanning for projects...
[INFO] ------------------------------------------------------------------------
[INFO] Building MorphologicalAnalysis
[INFO] task-segment: [compile]
[INFO] ------------------------------------------------------------------------
...(snip)
[INFO] [resources:resources {execution: default-resources}]
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] skip non existing resourceDirectory /home/mikoto/projects/maven/MorphologicalAnalysis/src/main/resources
...(snip)
[INFO] [compiler:compile {execution: default-compile}]
[INFO] Compiling 1 source file to /home/mikoto/projects/maven/MorphologicalAnalysis/target/classes
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESSFUL
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 15 seconds
[INFO] Finished at: Sat Jan 05 04:17:34 JST 2013
[INFO] Final Memory: 11M/88M
[INFO] ------------------------------------------------------------------------
oh...。また大量にダウンロードが。 とはいえ成功。 target が作成されていますね。
tree
.
├── pom.xml
├── src
│ ├── main
│ │ └── java
│ │ └── jp
│ │ └── dip
│ │ └── oyasirazu
│ │ └── morphologicalanalysis
│ │ └── App.java
│ └── test
│ └── java
│ └── jp
│ └── dip
│ └── oyasirazu
│ └── morphologicalanalysis
│ └── AppTest.java
└── target
└── classes
└── jp
└── dip
└── oyasirazu
└── morphologicalanalysis
└── App.class
19 directories, 4 files
4. 雛形プロジェクトのテスト実行
テストもするよ。
mvn test
[INFO] Scanning for projects...
[INFO] ------------------------------------------------------------------------
[INFO] Building MorphologicalAnalysis
[INFO] task-segment: [test]
[INFO] ------------------------------------------------------------------------
...(snip)
[INFO] [resources:resources {execution: default-resources}]
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] skip non existing resourceDirectory /home/mikoto/projects/maven/MorphologicalAnalysis/src/main/resources
[INFO] [compiler:compile {execution: default-compile}]
[INFO] Nothing to compile - all classes are up to date
[INFO] [resources:testResources {execution: default-testResources}]
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] skip non existing resourceDirectory /home/mikoto/projects/maven/MorphologicalAnalysis/src/test/resources
...(snip)
[INFO] [compiler:testCompile {execution: default-testCompile}]
[INFO] Compiling 1 source file to /home/mikoto/projects/maven/MorphologicalAnalysis/target/test-classes
...(snip)
[INFO] [surefire:test {execution: default-test}]
[INFO] Surefire report directory: /home/mikoto/projects/maven/MorphologicalAnalysis/target/surefire-reports
...(snip)
-------------------------------------------------------
T E S T S
-------------------------------------------------------
Running jp.dip.oyasirazu.morphologicalanalysis.AppTest
Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.093 sec
Results :
Tests run: 1, Failures: 0, Errors: 0, Skipped: 0
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESSFUL
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 23 seconds
[INFO] Finished at: Sat Jan 05 04:26:49 JST 2013
[INFO] Final Memory: 17M/154M
[INFO] ------------------------------------------------------------------------
mmm。 成功ですね。 テスト用のクラスとテスト結果が出力されています。
tree
.
├── pom.xml
├── src
│ ├── main
│ │ └── java
│ │ └── jp
│ │ └── dip
│ │ └── oyasirazu
│ │ └── morphologicalanalysis
│ │ └── App.java
│ └── test
│ └── java
│ └── jp
│ └── dip
│ └── oyasirazu
│ └── morphologicalanalysis
│ └── AppTest.java
└── target
├── classes
│ └── jp
│ └── dip
│ └── oyasirazu
│ └── morphologicalanalysis
│ └── App.class
├── surefire
├── surefire-reports
│ ├── jp.dip.oyasirazu.morphologicalanalysis.AppTest.txt
│ └── TEST-jp.dip.oyasirazu.morphologicalanalysis.AppTest.xml
└── test-classes
└── jp
└── dip
└── oyasirazu
└── morphologicalanalysis
└── AppTest.class
26 directories, 7 files
- Javadoc 作成
Javadoc 作るよ。
mvn javadoc:javadoc
[INFO] Scanning for projects...
[INFO] Searching repository for plugin with prefix: 'javadoc'.
[INFO] ------------------------------------------------------------------------
[INFO] Building MorphologicalAnalysis
[INFO] task-segment: [javadoc:javadoc]
[INFO] ------------------------------------------------------------------------
[INFO] Preparing javadoc:javadoc
[INFO] No goals needed for project - skipping
[INFO] [javadoc:javadoc {execution: default-cli}]
[INFO]
...(snip)
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESSFUL
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 29 seconds
[INFO] Finished at: Sat Jan 05 04:38:25 JST 2013
[INFO] Final Memory: 20M/194M
[INFO] ------------------------------------------------------------------------
はいできた。
tree
.
├── pom.xml
├── src
│ ├── main
│ │ └── java
│ │ └── jp
│ │ └── dip
│ │ └── oyasirazu
│ │ └── morphologicalanalysis
│ │ └── App.java
│ └── test
│ └── java
│ └── jp
│ └── dip
│ └── oyasirazu
│ └── morphologicalanalysis
│ └── AppTest.java
└── target
├── classes
│ └── jp
│ └── dip
│ └── oyasirazu
│ └── morphologicalanalysis
│ └── App.class
├── site
│ └── apidocs
│ ├── allclasses-frame.html
│ ├── allclasses-noframe.html
│ ├── constant-values.html
│ ├── deprecated-list.html
│ ├── help-doc.html
│ ├── index-all.html
│ ├── index.html
│ ├── jp
│ │ └── dip
│ │ └── oyasirazu
│ │ └── morphologicalanalysis
│ │ ├── App.html
│ │ ├── class-use
│ │ │ └── App.html
│ │ ├── package-frame.html
│ │ ├── package-summary.html
│ │ ├── package-tree.html
│ │ └── package-use.html
│ ├── overview-tree.html
│ ├── package-list
│ ├── resources
│ │ ├── background.gif
│ │ ├── tab.gif
│ │ ├── titlebar_end.gif
│ │ └── titlebar.gif
│ └── stylesheet.css
├── surefire
├── surefire-reports
│ ├── jp.dip.oyasirazu.morphologicalanalysis.AppTest.txt
│ └── TEST-jp.dip.oyasirazu.morphologicalanalysis.AppTest.xml
└── test-classes
└── jp
└── dip
└── oyasirazu
└── morphologicalanalysis
└── AppTest.class
34 directories, 27 files
target/site/apidocs に作成されるようだ。
- サイト作成
サイトもできるらしい。
mvn site
[INFO] Scanning for projects...
[INFO] ------------------------------------------------------------------------
[INFO] Building MorphologicalAnalysis
[INFO] task-segment: [site]
[INFO] ------------------------------------------------------------------------
...(snip)
[INFO] Unable to find resource 'org.mortbay.jetty:jetty-util:pom:6.1.5' in repository codehaus.org (http://snapshots.repository.codehaus.org)
...(snip)
[INFO] Unable to find resource 'org.mortbay.jetty:jetty-util:pom:6.1.5' in repository apache.m2.incubator (http://people.apache.org/repo/m2-snapshot-repository/)
...(snip)
[INFO] Unable to find resource 'org.mortbay.jetty:servlet-api-2.5:pom:6.1.5' in repository codehaus.org (http://snapshots.repository.codehaus.org)
...(snip)
[INFO] Unable to find resource 'org.mortbay.jetty:servlet-api-2.5:pom:6.1.5' in repository apache.m2.incubator (http://people.apache.org/repo/m2-snapshot-repository/)
...(snip)
[INFO] Unable to find resource 'org.mortbay.jetty:jetty-util:jar:6.1.5' in repository codehaus.org (http://snapshots.repository.codehaus.org)
...(snip)
[INFO] Unable to find resource 'org.mortbay.jetty:jetty-util:jar:6.1.5' in repository apache.m2.incubator (http://people.apache.org/repo/m2-snapshot-repository/)
...(snip)
[INFO] Unable to find resource 'org.mortbay.jetty:servlet-api-2.5:jar:6.1.5' in repository codehaus.org (http://snapshots.repository.codehaus.org)
...(snip)
[INFO] Unable to find resource 'org.mortbay.jetty:servlet-api-2.5:jar:6.1.5' in repository apache.m2.incubator (http://people.apache.org/repo/m2-snapshot-repository/)
...(snip)
[INFO] [site:site {execution: default-site}]
[INFO] artifact org.apache.maven.skins:maven-default-skin: checking for updates from central
...(snip)
[INFO] Generating "Plugin Management" report.
...(snip)
[INFO] Generating "Mailing Lists" report.
[INFO] Generating "Continuous Integration" report.
[INFO] Generating "Project License" report.
[INFO] Generating "Project Team" report.
[INFO] Generating "Source Repository" report.
[INFO] Generating "About" report.
[INFO] Generating "Issue Tracking" report.
[INFO] Generating "Project Summary" report.
[INFO] Generating "Dependencies" report.
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESSFUL
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 1 minute 50 seconds
[INFO] Finished at: Sat Jan 05 04:44:54 JST 2013
[INFO] Final Memory: 29M/193M
[INFO] ------------------------------------------------------------------------
いろんな項目ができたみたい。
tree
.
├── pom.xml
├── src
│ ├── main
│ │ └── java
│ │ └── jp
│ │ └── dip
│ │ └── oyasirazu
│ │ └── morphologicalanalysis
│ │ └── App.java
│ └── test
│ └── java
│ └── jp
│ └── dip
│ └── oyasirazu
│ └── morphologicalanalysis
│ └── AppTest.java
└── target
├── classes
│ └── jp
│ └── dip
│ └── oyasirazu
│ └── morphologicalanalysis
│ └── App.class
├── site
│ ├── apidocs
│ │ ├── allclasses-frame.html
│ │ ├── allclasses-noframe.html
│ │ ├── constant-values.html
│ │ ├── deprecated-list.html
│ │ ├── help-doc.html
│ │ ├── index-all.html
│ │ ├── index.html
│ │ ├── jp
│ │ │ └── dip
│ │ │ └── oyasirazu
│ │ │ └── morphologicalanalysis
│ │ │ ├── App.html
│ │ │ ├── class-use
│ │ │ │ └── App.html
│ │ │ ├── package-frame.html
│ │ │ ├── package-summary.html
│ │ │ ├── package-tree.html
│ │ │ └── package-use.html
│ │ ├── overview-tree.html
│ │ ├── package-list
│ │ ├── resources
│ │ │ ├── background.gif
│ │ │ ├── tab.gif
│ │ │ ├── titlebar_end.gif
│ │ │ └── titlebar.gif
│ │ └── stylesheet.css
│ ├── css
│ │ ├── maven-base.css
│ │ ├── maven-theme.css
│ │ ├── print.css
│ │ └── site.css
│ ├── dependencies.html
│ ├── images
│ │ ├── close.gif
│ │ ├── collapsed.gif
│ │ ├── expanded.gif
│ │ ├── external.png
│ │ ├── icon_error_sml.gif
│ │ ├── icon_info_sml.gif
│ │ ├── icon_success_sml.gif
│ │ ├── icon_warning_sml.gif
│ │ ├── logos
│ │ │ ├── build-by-maven-black.png
│ │ │ ├── build-by-maven-white.png
│ │ │ └── maven-feather.png
│ │ └── newwindow.png
│ ├── index.html
│ ├── integration.html
│ ├── issue-tracking.html
│ ├── license.html
│ ├── mail-lists.html
│ ├── plugin-management.html
│ ├── project-info.html
│ ├── project-summary.html
│ ├── source-repository.html
│ └── team-list.html
├── surefire
├── surefire-reports
│ ├── jp.dip.oyasirazu.morphologicalanalysis.AppTest.txt
│ └── TEST-jp.dip.oyasirazu.morphologicalanalysis.AppTest.xml
└── test-classes
└── jp
└── dip
└── oyasirazu
└── morphologicalanalysis
└── AppTest.class
37 directories, 54 files
target/site 下にいろいろできたみたい。 いろいろと書くべきものがあるのねぇといった具合で眺めるだけにしておこう。
- ローカルリポジトリへのインストール
アンインストール方法をまだ知らないので保留。 clean して今日はここまで。
[INFO] Scanning for projects...
[INFO] ------------------------------------------------------------------------
[INFO] Building MorphologicalAnalysis
[INFO] task-segment: [clean]
[INFO] ------------------------------------------------------------------------
...(snip)
[INFO] [clean:clean {execution: default-clean}]
[INFO] Deleting file set: /home/mikoto/projects/maven/MorphologicalAnalysis/target (included: [\*\*], excluded: [])
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESSFUL
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 8 seconds
[INFO] Finished at: Sat Jan 05 06:48:58 JST 2013
[INFO] Final Memory: 6M/55M
[INFO] ------------------------------------------------------------------------
うん、きれいになってますね。
tree
.
├── pom.xml
└── src
├── main
│ └── java
│ └── jp
│ └── dip
│ └── oyasirazu
│ └── morphologicalanalysis
│ └── App.java
└── test
└── java
└── jp
└── dip
└── oyasirazu
└── morphologicalanalysis
└── AppTest.java
13 directories, 3 files