modal_soulの記録

バイクおじさんの日常とメンテナンス、そしてその記録

バイクおじさんの日常とメンテナンス

Play! framework 2.0 betaをEclipseで使おう

IDEは主にEclipseを使っているので、Play! frameworkもEclipseを使おうと思います。  これまでは、eclipsifyコマンドを使ってplayプロジェクトをEclipseプロジェクトに変換、でしたが  Play! framework2.0からは、sbteclipseを使ってEclipseプロジェクトへ変換するようです。

というわけで、Play!プロジェクトのEclipseプロジェクト化をやってみます。下記のページを参考にしました。

Play framework 2.0 betaが出たようです3 – Eclipse+sbtで開発しよう

Playプロジェクトの作成

ScalaベースのHelloWorldプロジェクトを作成します。

 >play new HelloWorld

project/plugins.sbtファイルの編集

resolvers ++= Seq(
    DefaultMavenRepository,
    Resolver.url("Play", url("http://download.playframework.org/ivy-releases/"))(Resolver.ivyStylePatterns),
    "Typesafe Repository" at "http://repo.typesafe.com/typesafe/releases/"
)
 
resolvers += Classpaths.typesafeResolver  //追記
 
addSbtPlugin("com.typesafe.sbteclipse" % "sbteclipse" % "1.4.0") //追記
 
libraryDependencies += "play" %% "play" % "2.0-beta"

ここで追記しているものが何なのか、少し調べてみます。  下記のページを参考にしました。

harrah / xsbt

上の追記は、ビルド定義にライブラリ依存性を追加しているようです。これでsbtが依存関係を解決してくれるようです。

To add a plugin, do the same thing but recursed one level. We want the build definition project to have a new dependency. That means changing the libraryDependencies setting for the build definition of the build definition.

The build definition of the build definition, if your project is hello, would be in hello/project/*.sbt and hello/project/project/*.scala.

The simplest "plugin" has no special sbt support; it's just a jar file. For example, edit hello/project/build.sbt and add this line:
libraryDependencies += "net.liftweb" % "lift-json" % "2.0"

playコマンドを起動していれば、reload

※ちなみに、sbtファイルの休業空行は意味があるらしいので気をつけましょう。空行を入れずにreloadするとエラーになりました。

\HelloWorld\project\plugins.sbt:6: error: eof expected but ';' found.,

Eclipseプロジェクト化

sbt上で、eclipse create-srcを実行

[HelloWorld] $ eclipse create-src
[info] About to create an Eclipse project for you.
[info] Please hang on, because it might be necessary to perform one or more updates and this might take some time ...
[info] Updating {file://HelloWorld/}HelloWorld...
[info] Done updating.
[info] Successfully created Eclipse project files. Please select the appropriate Eclipse plugin for Scala 2.9.1!

Eclipseにプロジェクトをインポート

インポートしたところ、エラーが発生。

20111207003442

ビルドパスの設定を見たところ、同じパスが重複して登録されていたので、紹介されていた通り削除。ビルドパスに「target/scala-2.9.1/classes」を追加し、アプリ起動後1度アクセスして、Refreshしましたが直らず。。

アプリケーションは動いているのですが、なんか気持ち悪いなぁ。。また今度調べます。