DropWizard初めの第一歩

私はここで盛大に躓きました(笑)
http://www.dropwizard.io/ の「Getting Started」を見ても全然はじめられません。最初に「Maven」という単語が出てきて読む気を無くしますwしかも英語だし。
というわけで、以下のようにしてまずはサンプルプロジェクトを作ってみましょう

  • maven3の最新版(3.3.3)をインストール
  • % mvn archetype:generate > a.txt
  • と実行して、dropwizard 関連のプロジェクトを探す
    • 9: remote -> br.com.ingenieux:elasticbeanstalk-docker-dropwizard-webapp-archetype (A Maven Archetype for Publishing Dropwizard-based Services on AWS' Elastic Beanstalk Service)
    • 311: remote -> eu.clarin.weblicht:weblicht-nentities-ws-dw-archetype (An archetype for creating weblicht web services with dropwizard. This archetype provides debian and redhat packaging.)
    • 335: remote -> io.dropwizard.archetypes:java-simple (-)
    • 1360: remote -> pl.najda:dw-archetype (Archetype for building an initial structure of directories and files for Dropwizard web services. Contains a simple web service (available at http://localhost:8082/hello-world) with sources - to simplify development.)
  • 335で作りましょう。以下の赤字だけ入力して、後はEnterキーを連打。


% mvn archetype:generate
Choose a number or apply filter (format: [groupId:]artifactId, case sensitive contains): 628: 335
Choose io.dropwizard.archetypes:java-simple version:
1: 0.8.0-rc2
2: 0.8.0-rc3
3: 0.8.0-rc4
4: 0.8.0-rc5
5: 0.8.0
6: 0.8.1-rc2
7: 0.8.1
8: 0.8.2
9: 0.9.0-rc1
10: 0.9.0-rc2
11: 0.9.0-rc3
Choose a number: 11: 8
Define value for property 'groupId': : Sample001
Define value for property 'artifactId': : Sample001
Define value for property 'version': 1.0-SNAPSHOT: :
Define value for property 'package': Sample001: :
[INFO] Using property: description = null
Define value for property 'name': : Sample001
[INFO] Using property: shaded = true
Confirm properties configuration:
groupId: Sample001
artifactId: Sample001
version: 1.0-SNAPSHOT
package: Sample001
description: null
name: Sample001
shaded: true
Y: :
[INFO] ----------------------------------------------------------------------------
[INFO] Using following parameters for creating project from Archetype: java-simple:0.8.2
[INFO] ----------------------------------------------------------------------------
[INFO] Parameter: groupId, Value: Sample001
[INFO] Parameter: artifactId, Value: Sample001
[INFO] Parameter: version, Value: 1.0-SNAPSHOT
[INFO] Parameter: package, Value: Sample001
[INFO] Parameter: packageInPathFormat, Value: Sample001
[INFO] Parameter: package, Value: Sample001
[INFO] Parameter: version, Value: 1.0-SNAPSHOT
[INFO] Parameter: name, Value: Sample001
[INFO] Parameter: groupId, Value: Sample001
[INFO] Parameter: description, Value: null
[INFO] Parameter: shaded, Value: true
[INFO] Parameter: artifactId, Value: Sample001
[INFO] project created from Archetype in dir: C:\work\src\maven\Sample001
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 01:35 min
[INFO] Finished at: 2015-07-26T17:24:25+09:00
[INFO] Final Memory: 10M/26M
[INFO] ------------------------------------------------------------------------

  • すると、Sample001 フォルダが作られて、その中に色々なファイルが作られていますので、ビルドして実行してみましょう
  • % cd Sample001
  • % mvn package
  • % java -jar target\Sample001-1.0-SNAPSHOT.jar server
  • 無事起動したら(何やらWARNINGはいっぱい出ますけど気にしない)「http://localhost:8081/」にアクセスしてみましょう


Operational Menu
・Metrics
Ping
・Threads
・Healthcheck
ってのが出ればとりあえず成功。CTRL+Cで終了できます。