経緯
怖くないScala勉強会に参加するにあたり、個人的にハマったので、Eclipse LunaでScalaを準備する方法を整理しておく。
scala sbt, Typesafe Activatorの準備
scala-sbtとTypesafe Activatorをインストールする。
$ brew install sbt
$ brew install typesafe-activator
sbtを一度起動して、関連ファイルをダウンロードしておく。
$ sbt
後でScalaプロジェクトをEclipseプロジェクトに変換するために、Typesafe ActivatorにEclipseプラグインの設定を通しておく。
勉強会の事前資料や他のページの検索結果には、Scalaプロジェクトごとに設定する様な方法が書いてあるんだけど、私の環境ではどうしてもうまくいかなかった。同様の事例を参考に、 ~/.sbt/plugins/plugins.sbt に設定を記載する。空行は省略しない。
$ vi ~/.sbt/plugins/plugins.sbt
resolvers += Classpaths.typesafeResolver
addSbtPlugin("com.typesafe.sbteclipse" % "sbteclipse-plugin" % "2.5.0")
Scala IDE for Eclipseの準備
EclipseにScala IDEをインストールする。
2014年10月10日現在、Marketplaceからインストールすると、4.3(Kelper)まで対応のScala IDEがインストールされてしまい、4.4(Luna)では動作しない。
Scala IDEのMilestoneの情報を元に、EclipseのHelp→Install New Software から
http://download.scala-ide.org/sdk/lithium/e44/scala211/dev/site
を Available Software Sitesに追加してインストールする。
Scalaプロジェクトの作成とEclipseへのインポート
$ activator ui
ブラウザでactivatorのホーム画面が表示されるので、メニューから'Hello Scala!'を選択する。
プロジェクトの作成パスを聞かれるので、好きなパスを入力(Ex: /path/to/hello-scala)して、'Create'ボタンを作成。
プロジェクトパスに移動して、hello-scalaをEclipse用のプロジェクトに変換する。
$ cd /path/to/hello-scala
$ sbt eclipse
変換処理が終わり次第、EclipseのFile→Importでインポートして、Scalaプロジェクトとして読み込めることを確認して完了。
実行
Eclipse で Run → Run As → Scala Application を実行する。
もしくは、プロジェクトパスに移動して、activatorのコンソールで実行する。
$ cd /path/to/hello-scala
$ activator console
scala> Hello.main(null)
Hello, world!
参考
https://github.com/mike-neck/scala-study
http://lewuathe.com/blog/2013/09/13/sbttoeclipsedescalakai-fa-huan-jing/
http://thachinohe.hatenablog.com/entry/scala_abc/004