MavenでHello World(実行編)
プロジェクトが作成できたので、次はこれをビルドしよう。jarプラグインのjarゴールを使うといいらしいのでこれを実行。
C:\home\project\helloworld>maven jar:jar
__ __
\/ | __ _Apache__ ___ | ||||||
\/ | / _` \ V / -_) ' \ ~ intelligent projects ~ | ||||||
_ | _\__,_ | \_/\___ | _ | _ | v. 1.0-rc3 |
build:start:
java:prepare-filesystem:
java:compile:
[echo] Compiling to C:\home\project\helloworld/target/classes
java:jar-resources:
Copying 1 file to C:\home\project\helloworld\target\classes
test:prepare-filesystem:
[mkdir] Created dir: C:\home\project\helloworld\target\test-classes
[mkdir] Created dir: C:\home\project\helloworld\target\test-reports
test:test-resources:
test:compile:
[javac] Compiling 3 source files to C:\home\project\helloworld\target\test-classes
test:test:
[junit] Running example.app.AppTest
[junit] Tests run: 1, Failures: 0, Errors: 0, Time elapsed: 0.17 sec
jar:jar:
[jar] Building jar: C:\home\project\helloworld\target\app-1.0.jar
BUILD SUCCESSFUL
Total time: 7 seconds
Finished at: Sun May 30 01:51:46 JST 2004jarファイルを作る前にテストも実行してる。でも"NaughtyTest"はテストされてないのかな?project.xmlを除いてみたら、unitTestのときはNaughtyTest.javaを除外するような記述があった。このテンプレートを使うときは気をつけないといけないかな。
実行後には、以下の構成で出力されていた。
一応、動作確認。
target/
+--classes/
+--app.properties
+--example/
+--app/
+--App.class
+--test-classes/
+--example/
+--app/
+--AbstractTestCase.class
+--AppTest.class
+--NaughtyTest.class
+--test-reports/
+--TEST-example.app.AppTest.txt
+--TEST-example.app.AppTest.xml
+--app-1.0.jar
みごと成功。ほぼ何の設定もなしで、テスト実行やjarファイル作成まで簡単にできちゃいました。これは便利だわ。
C:\home\project\helloworld>java -cp target\app-1.0.jar example.app.App
Hello World!