LoginSignup
28
29

More than 5 years have passed since last update.

PlayFramework 2.4:Ebeanがプラグイン化されたのでくっ付ける

Last updated at Posted at 2015-06-18

発端

Play 2.4 Migration Guide
https://www.playframework.com/documentation/2.4.x/Migration24

Ebean dependencyの項
Ebeanを外部プロジェクト化することで、
Playのライフサイクルとは独立したライフサイクルを持たせ、
互いに依存しないようにする……らしきことが書いてある

さらに、Play2.3まではplay.db.ebean.Modelを継承してModelクラスとしていたが、
このパッケージは非推奨になり、com.avaje.ebean.Modelに置き換えられた

編集したファイルと追記内容

公式ドキュメントとほとんど一緒

  • project/plugins.sbt
    以下を追記
    addSbtPlugin("com.typesafe.sbt" % "sbt-play-ebean" % "1.0.0")
  • build.sbt
    libraryDependenciesにjavaEbeanを書いてはいけなくなった
    プラグインとして有効化する
    lazy val myProject = (project in file(".")).enablePlugins(PlayJava, PlayEbean)
  • application.conf
    どのパッケージ以下をモデルにするのかを設定
    ebean.default = ["models.*"]

終わったらactivator updateで更新
その後はいつものように使うことができる

play.db.ebeanからcom.avaje.ebeanに移行して変わること

  • Finderが非推奨になった

Finderの代わりにFindを使うと良いらしい

public static Finder<Long,String> finder = new Finder<>(Long.class, String.class);

public static final Find<Long,String> finder = new Find<Long,String>(){};

https://github.com/ebean-orm/avaje-ebeanorm
https://github.com/ebean-orm/avaje-ebeanorm/issues/282

※ Finderのままこう書いても良いらしい
public static final Finder<Long, User> finder = new Finder<Long, User>(User.class);

番外 activator eclipseコマンドが動かないとき

何も考えずこのコマンドを打ったら以下のようなエラーが出た
eclipse_error.png

対策(2015/06/25更新)

Setting up your preferred IDE
https://www.playframework.com/documentation/2.4.x/IDE

上記によるとsbteclipseプラグインの4.0.0以上が必要らしい

しかし現時点でsbteclipseのreleasesにバージョン4.0.0は存在せず、
そのままコピペしてもライブラリを見つけられない(いずれ出てくるものとして予めこう書いてあるのだろうか……)
https://github.com/typesafehub/sbteclipse

とりあえずバージョン4.0.0-RC2を使えば良さそう
以下をproject/plugins.sbtにコピペして解決
addSbtPlugin("com.typesafe.sbteclipse" % "sbteclipse-plugin" % "4.0.0-RC2")

4.0.0リリース!
addSbtPlugin("com.typesafe.sbteclipse" % "sbteclipse-plugin" % "4.0.0")

28
29
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
28
29