PlayFramework/play2.3のインストール

(3291d) 更新


ソフトウェア/PlayFramework?

概要

思った以上にいろいろ躓いたので。

activator 同梱の play2.3 をダウンロード&解凍

http://www.playframework-ja.org/download

の「オフライン版(342M)」から "typesafe-activator-1.2.2.zip" をダウンロード

LANG:console
> unzip typesafe-activator-1.2.2.zip
> cd activator-1.2.2
> activator.bat
 A Java JDK is not installed or can't be found.
 
 Please go to
   http://www.oracle.com/technetwork/java/javase/downloads/index.html
 and download a valid Java JDK and install before running Activator.
 
 If you think this message is in error, please check
 your environment variables to see if "java.exe" and "javac.exe" are
 available via JAVA_HOME or PATH.

JDK8 をダウンロード&インストール

http://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html

から、"jdk-8u45-windows-x64.exe" をダウンロード&インストール。

LANG:console
> javac
 'javac' は、内部コマンドまたは外部コマンド、
 操作可能なプログラムまたはバッチ ファイルとして認識されていません。
> "C:\Program Files\Develop\jdk1.8.0_45\bin"\javac
 使用方法: javac <options> <source files>
 使用可能なオプションには次のものがあります。
   -g                         すべてのデバッグ情報を生成する
   -g:none                    デバッグ情報を生成しない
   -g:{lines,vars,source}     いくつかのデバッグ情報のみを生成する
   ...

環境変数の設定

LANG:console
> set JAVA_HOME="C:\Program Files\Develop\jdk1.8.0_45"
> activator
 Files\Develop\jdk1.8.0_45""=="" の使い方が誤っています。

あれ?
https://docs.oracle.com/cd/E19416-01/820-5482/inst_set_jdk_windows_t/

えーと・・・

LANG:console
> set JAVA_HOME=C:\Program Files\Develop\jdk1.8.0_45
> activator
 コマンドの構文が誤っています。

そういうこと?!

どうやらこっちが正しそうだけれど、まだ動かない。

http://stackoverflow.com/questions/24116031/typesafe-activator-java-jdk-not-installed-or-cant-be-found

これか。

LANG:console
> set PATH=C:\Program Files\Develop\jdk1.8.0_45\bin;%PATH%
> activator
 'findstr' は、内部コマンドまたは外部コマンド、
 操作可能なプログラムまたはバッチ ファイルとして認識されていません。
 コマンドの構文が誤っています。

ん???

なぜか PATH に Windows や Windows\System32 が含まれていなかった。

LANG:console
> set PATH=%PATH%;C:\Windows;C:\Windows\System32
> activator
 Getting com.typesafe.activator activator-launcher 1.2.2 ...
 downloading file:////(activator_path)/repository/com.typesafe.activator/activator-launcher/1.2.2/jars/activator-launcher.jar ...
       [SUCCESSFUL ] com.typesafe.activator#activator-launcher;1.2.2!activator-launcher.jar (25ms)
 ...
 
   :: retrieving :: org.scala-sbt#boot-scala
         confs: [default]
         6 artifacts copied, 0 already retrieved (24060kB/72ms)
  Did not detect an activator project in this directory.
 
  There are three ways to run activator:
 
  1. Recommended: try `activator ui` to create a project in the UI
  2. Use `activator new` to create a project on the command line
  3. Load an existing project by re-running activator in a project directory

ようやく動きそう。

activator ui を試す

LANG:console
> activator ui
 Checking for a newer version of Activator (current version 1.2.2)...
    ... found updated version of Activator 1.3.2 (replacing 1.2.2)
    ... Please download a new Activator by hand at http://typesafe.com/ (the late
 st version 1.3.2 isn't compatible with this launcher, generation 0 vs. 1).
 Getting com.typesafe.activator activator-ui 1.2.2 ...
 downloading file:////(activator_path)/repository/com.typesafe.activator/activator-ui/1.2.2/jars/activator-ui.jar ...
         [SUCCESSFUL ] com.typesafe.activator#activator-ui;1.2.2!activator-ui.jar (246ms)
 ...

 :: retrieving :: org.scala-sbt#boot-app
       confs: [default]
       76 artifacts copied, 0 already retrieved (62932kB/1518ms)
 FOUND REPO = activator-local @ file:////(ativator_path)/repository
 Play server process ID is 294224
 [info] play - Application started (Prod)
 [info] play - Listening for HTTP on /127.0.0.1:8888
 [INFO] [04/21/2015 15:35:47.498] [default-akka.actor.default-dispatcher-7] [akka://default/user/home-socket-1] Firing up web socket

となって、勝手にブラウザで http://127.0.0.1:888/ が開いた。

Typesafe Activator-00 startup.png

同時に 「Windows セキュリティの重要な警告」が開いた。

windows-security-warning.png

localhost からの接続のみ受け付ければよいので、念のためチェックを外してキャンセル。

Hello Scala! を作成

Hello Scala! を選んで Create すると、

http://127.0.0.1:888/app/hello-scala

に遷移した。

Typesafe Activator-01 created.png

"Run the app>" を選ぶと、左のメニューで "Run" が選択された状態になって、 中央の Logs の部分に "Hello, world!" が表示された。

左のメニューで "Code" を選び、"src/main/scala/Hello.scala" を選ぶと、 中央にファイル内容が表示されて、その場で編集可能になる。

"Hello, world!" を "Hello, world!!!" と地味に編集して、Ctrl+S で保存。

左のメニューで "Run" を押すと、すでに Logs の部分には "Hello, world!!!" が表示されている。

裏でコンパイルしているはずなんだけれど、あまりにシームレスでびっくりする。

あれ?この例は Play Framework に載っていない最低限の物なのか。

AngularJS Play Mongo というのを試す

もっとまともな tutorial を、ということで、これなら

  • angularjs
  • coffeescript
  • play
  • guice
  • mongodb
  • reactive-mongo
  • bootstrapui
  • rest
  • scala

のタグが付いていて、一通りのことができそう。

Create 後、Run してから "Open the app: http://localhost:9000" のリンクを踏むと "Modern Web Template" というタイトルのページが表示されました。 ビルドには結構時間がかかる印象。

で、表示されたフォームを試してみると、そのままではデータの更新ができないみたいです?

"Test" メニューでテストを実行しても controllers.UsersIT でエラーが出ます。
→ エラーの詳細はどうやったら見られるのだろう???

ソースを見ると UsersIT のテストは json によるデータ更新のテストなので、 やはり何かがうまく行っていない感じ。

テストのログをどこで見られるのか、結局解らない。

あと、テストにえらく時間がかかるのだけれどこんな物なのだろうか???

ん?

"Inspect" メニューの所に、

No requests found. There could be two reasons for this: 
either there haven't been any requests to your Play application yet or 
you're running an unsupported Play version (>2.3.0)

というメッセージが出ていた。

Play2.3.? はサポート外ということらしい orz

Play Slick Backbone Todo List Example というのを試す

あれ、これもだ。

No requests found. There could be two reasons for this: 
either there haven't been any requests to your Play application yet or 
you're running an unsupported Play version (>2.3.0)

バージョンを確かめる

ということで、[Inspect]-[Incoming Requests] を使うには Play Framework の 2.3.0 以下でないとダメらしい。同様に、[Inspect]-[Actors] なら Akka 2.3.3 以下。

一方、作成されたアプリケーションの build.sbt を見ると、

modern-web-template/build.sbt

LANG:scala
libraryDependencies ++= Seq(
  "com.google.inject" % "guice" % "3.0",
  "javax.inject" % "javax.inject" % "1",
  "org.reactivemongo" %% "play2-reactivemongo" % "0.10.5.0.akka23",
  "org.webjars" % "bootstrap" % "3.3.1",
  "org.webjars" % "angularjs" % "1.3.8",
  "org.webjars" % "angular-ui-bootstrap" % "0.12.0",
  "org.mockito" % "mockito-core" % "1.10.17" % "test")

play-scala-backbone-todo/build.sbt

LANG:scala
libraryDependencies ++= Seq(
  ws,
  "org.webjars" % "jquery" % "2.1.1",
  "org.webjars" % "requirejs" % "2.1.14-1",
  "org.webjars" % "backbonejs" % "1.1.2-2",
  "org.webjars" % "underscorejs" % "1.6.0-3",
  "org.webjars" % "dustjs-linkedin" % "2.4.0-1",
  "com.typesafe.play" %% "play-slick" % "0.8.0",
  "org.seleniumhq.selenium" % "selenium-firefox-driver" % "2.34.0"
)

等となっていて・・・これじゃバージョン解らないな。

http://stackoverflow.com/questions/26042915/how-can-i-download-play-framework-2-3-3

によれば Play のバージョンは、project/plugins.sbt で指定されているとのこと。

modern-web-template/project/plugins.sbt

LANG:scala
// Use the Play sbt plugin for Play projects
addSbtPlugin("com.typesafe.play" % "sbt-plugin" % "2.3.7")

play-scala-backbone-todo/project/plugins.sbt

LANG:scala
addSbtPlugin("com.typesafe.play" % "sbt-plugin" % "2.3.2")

確かに > 2.3.0 になっている。

git で履歴を取る

変更する前に git で履歴を取りたいけれど・・・

と思ったら、ちゃんと .gitignore が作られている。

LANG:console
$ cd play-scala-backbone-todo
$ git init
$ git add .
$ git status
 On branch master
 
 Initial commit
 
 Changes to be committed:
   (use "git rm --cached <file>..." to unstage)
 
         new file:   .gitignore
         new file:   LICENSE
         new file:   README.md
         new file:   activator
         new file:   activator-launch-1.2.2.jar
         new file:   activator.bat
         new file:   app/Globals.scala
         new file:   app/assets/css/main.less
         new file:   app/assets/js/app.coffee
         new file:   app/assets/js/main.coffee
         new file:   app/assets/js/modules/todo.coffee
         new file:   app/assets/js/router.coffee
         new file:   app/assets/templates/todoitem.tl
         new file:   app/controllers/Application.scala
         new file:   app/controllers/TodoController.scala
         new file:   app/models/Todo.scala
         new file:   app/views/index.scala.html
         new file:   app/views/main.scala.html
         new file:   build.sbt
         new file:   conf/application.conf
         new file:   conf/evolutions/default/1.sql
         new file:   conf/routes
         new file:   project/activator-sbt-eclipse-shim.sbt
         new file:   project/activator-sbt-idea-shim.sbt
         new file:   project/build.properties
         new file:   project/plugins.sbt
         new file:   public/images/favicon.png
         new file:   test/ApplicationSpec.scala
         new file:   test/IntegrationSpec.scala
$ git commit -m "initial commit"

こんな感じ。


Counter: 8037 (from 2010/06/03), today: 6, yesterday: 0