IntelliJ IDEA + PlayFramework

仕事でサーバーサイドJavaはSpringがメインっぽくやってるんですが、 やることに対して大げさすぎるというかなんというかなので調査目的でPlayFrameworkに手を出してみよう。 Struts?知らない子ですね…。

コンソール+エディタでもいいのでせっかく持ってるんだからってことでIDEを使おうとしていきなり時間を吸われたので 忘れないためメモ。

教科書は

Play Framework 2徹底入門 JavaではじめるアジャイルWeb開発

ScalaScalaを勉強した後にサラッと見直すような感じ?

Capter1

  1. (http://www.playframework-ja.org/download)が落ちてたので(http://www.playframework.com/download)からplay-2.2.3.zipをダウンロード。

  2. IntelliJからNewProject->Play 2 Module for JavaやるとModule作れないよ!エラー

  3. new Hoge -> ideaでOpenProjectやるとPlayHome認識しなくてRunでエラー

  4. new Hoge -> idea with-sources=yesでOpenProjectだとRun成功

ebifly10@mba # play
[info] Loading project definition from /Users/ebifly10/play/myapp/project
[info] Set current project to myapp (in build file:/Users/ebifly10/play/myapp/)
       _
 _ __ | | __ _ _  _
| '_ \| |/ _' | || |
|  __/|_|\____|\__ /
|_|            |__/

play 2.2.3 built with Scala 2.10.3 (running Java 1.7.0_51), http://www.playframework.com

> Type "help play" or "license" for more information.
> Type "exit" or use Ctrl+D to leave this console.

[myapp] $ idea with-sources=yes
[info] Updating {file:/Users/ebifly10/play/myapp/}myapp...
[info] Resolving org.hibernate.javax.persistence#hibernate-jpa-2.0-api;1.0.1.Final ..[info] Resolving org.fusesource.jansi#jansi;1.4 ...
[info] Done updating.
[info] Compiling 4 Scala sources and 2 Java sources to /Users/ebifly10/play/myapp/target/scala-2.10/classes...
[info] Creating IDEA module for project 'myapp' ...
[info] Running compile:managedSources ...
[info] Resolving org.hibernate.javax.persistence#hibernate-jpa-2.0-api;1.0.1.Final ..[info] Resolving org.fusesource.jansi#jansi;1.4 ...
[info] Excluding folder target
[info] Created /Users/ebifly10/play/myapp/.idea/IdeaProject.iml
[info] Created /Users/ebifly10/play/myapp/.idea
[info] Excluding folder /Users/ebifly10/play/myapp/target/scala-2.10/cache
[info] Excluding folder /Users/ebifly10/play/myapp/target/scala-2.10/classes
[info] Excluding folder /Users/ebifly10/play/myapp/target/scala-2.10/classes_managed
[info] Excluding folder /Users/ebifly10/play/myapp/target/resolution-cache
[info] Excluding folder /Users/ebifly10/play/myapp/target/streams
[info] Created /Users/ebifly10/play/myapp/.idea_modules/myapp.iml
[info] Created /Users/ebifly10/play/myapp/.idea_modules/myapp-build.iml

これで無事IDE側からRunできて(http://localhost:9000)でWelcome Pageに出会えました。

    public static Result index() {
        return ok(index.render("Your new application is ready."));
    }

Cannot resolve method 'ok(?)'

に遭遇した時は

import views.html.index;

を追加。 ワイルドカードでImportしてるんで動かない事もないんですが…。

気になった点は

  • play.api.data.Form

  • play.data.Form

なのかをIntelliJが上手く判別してくれていない気がする。 問題なく動くんだけど文法エラーっぽいのが出るのがあまり気持ちいものではない。 むしろ自分でもまだどっちがどっちなのか分かっていない。

補完面はeclipseもちょっと見てみたんだけどもっと残念な感じだった(プラグイン探しきれてない?)のでIntelliJで頑張ります。