Javaの常識を変えるらしいPlay Framework~チュートリアルの2~
! この記事はJavaの常識を変えるらしいPlay Frameworkの続きです.
というわけでチュートリアルを続けていきます。今日は飲み会なので張り切って行きましょう。
新しいアプリケーションの作成
activator
コマンドで簡単に新しいPlayアプリケーション作成できるらしい。ほい
$ activator new tutorial-app play-java Fetching the latest list of templates... OK, application "tutorial-app" is being created using the "play-java" template. To run "tutorial-app" from the command line, "cd tutorial-app" then: /home/user/play-test/tutorial-app/activator run To run the test for "tutorial-app" from the command line, "cd tutorial-app" then: /home/user/play-test/tutorial-app/activator test To run the Activator UI for "tutorial-app" from the command line, "cd tutorial-app" then: /home/user/play-test/tutorial-app/activator ui
おーなんかいろいろできた。ちなみにこれJavaですけどScala大好きっ子なら
$ activator new tutorial-app play-scala
でScalaアプリケーションもいけるみたいよ。 activator恐ろしい子・・・!そのうちまとめよう。 新しく作成されたディレクトリいって
activator
とか叩けばPlay consoleに入れるらしい、、、Play Console ...?多分次のチュートリアルでわかる気がする
実際何が作られるかは公式見た方が分かると思うので見よう。でも構造が個人的にわかりやすくてすごく好き。
Play Console
なんかよくわかんないけど、開発をサポートしてくれるらしい、ちなみにTabで補完効いた
まずはhelpコマンド、例えばrun
$ help run Runs a main class, passing along arguments provided on the command line.
なるほどmain class実行して引数に従ってゴニョゴニョしてくれるらしい
次、runコマンド
$ run [info] Updating {file:/home/user/play-test/tutorial-app/}root... [info] Resolving jline#jline;2.11 ... [info] downloading file:/home/user/activator-1.3.2/repository/org.scala-lang/scala-library/2.11.1/jars/scala-library.jar ... [info] [SUCCESSFUL ] org.scala-lang#scala-library;2.11.1!scala-library.jar (439ms) [info] downloading file:/home/user/activator-1.3.2/repository/com.typesafe.play/play-java_2.11/2.3.8/jars/play-java_2.11.jar .. [info] [SUCCESSFUL ] com.typesafe.play#play-java_2.11;2.3.8!play-java_2.11.jar (57ms) . . . --- (Running the application, auto-reloading is enabled) --- [info] play - Listening for HTTP on /0:0:0:0:0:0:0:0:9000 (Server started, use Ctrl+D to stop and go back to the console...)
最初run
した時はupdate多くていろいろ表示されるけど結局サーバー起動するよー、Ctrl+Dで止められるよーでいいんじゃなかろうか
でブラウザで適当にlocalhostに9000番でアクセスすれば下の画像みたいになる
sakuraVPSとかで借りてるサーバで動かしたいなら下のサイト参考にしてみるといいと思います。ぼくはそうしました。
nginxからPlay Frameworkを呼ぶ
ただ上記のままだとエラー出ちゃうので(上の図みたいな)locationの/play/を/playと変えたら動いた。
疲れたので今日はここまでで