Play! Scalaを Macで始める

Play! Scalaを Macで始める

久しぶりにPlay!に触ったら昔とだいぶ違ったのでメモ。

今回の目標

  1. Play!をインストール
  2. プロジェクトのスケルトンを作成
  3. IntellijIDEAで開発スタートする準備をする
    ところまでが目標。

Play!のインストール

しばらくぶりにPlay!にさわろうと思ったら、playコマンドがなくなっていて、今はtypesafe-activatorにその役目を譲っているらしいので、typesafe-activatorをインストールします。
typesafe-activatorとその開発元のTypesafe社は http://osdn.jp/magazine/13/08/15/150000 http://osdn.jp/magazine/11/05/13/0340257 この辺りをご参照ください。
(私の所属している会社も最近パートナーの末席に仲間入りしました。 https://www.typesafe.com/partners/systemintegrator-partners#community )

typesafe-activatorはhomebrewでインストールできるので、おもむろにbrewコマンドでインストールします。

1
2
3
4
5
$ brew install typesafe-activator *[feature/merge]
==> Downloading https://homebrew.bintray.com/bottles/typesafe-activator-1.3.3.mavericks.bottle.tar.gz
######################################################################## 100.0%
==> Pouring typesafe-activator-1.3.3.mavericks.bottle.tar.gz
🍺 /usr/local/Cellar/typesafe-activator/1.3.3: 4 files, 1.2M

プロジェクトのスケルトンを作成

プロジェクトの作成

playコマンドの代わりにactivatorコマンドを使用してスケルトンを作成します。
いくつか質問されるので順次答えます。

  1. テンプレートは 6 の play-scala
  2. アプリケーション名は任意のものを指定
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
$ activator new
Fetching the latest list of templates...
Browse the list of templates: http://typesafe.com/activator/templates
Choose from these featured templates or enter a template name:
1) minimal-akka-java-seed
2) minimal-akka-scala-seed
3) minimal-java
4) minimal-scala
5) play-java
6) play-scala
(hit tab to see a list of all templates)
> 6
Enter a name for your application (just press enter for 'play-scala')
> your-project-name
OK, application "your-project-name" is being created using the "play-scala" template.
To run "your-project-name" from the command line, "cd your-project-name" then:
/Users/enjoji/projects/your-project-name/activator run
To run the test for "your-project-name" from the command line, "cd your-project-name" then:
/Users/enjoji/projects/your-project-name/activator test
To run the Activator UI for "your-project-name" from the command line, "cd your-project-name" then:
/Users/enjoji/projects/your-project-name/activator ui

動作確認

プロジェクトが出来たので試しに起動してみます。
プロジェクトのディレクトリに移動し、 activator run を実行しエラーなく起動すればOKです。

1
2
3
$ activator run
Getting org.scala-sbt sbt 0.13.8 ...
downloading https://repo1.maven.org/maven2/org/scala-lang/scala-compiler/2.10.4/scala-compiler-2.10.4.jar

どうやらJava8じゃないと起動しない模様

IntelliJで使う

Intellij Install

  • まずは IntalliJ IDEA をインストールします。

  • 次に必要なプラグインをインストールします

    • Plugin
      • SBT
      • Scala
        プラグインをインストール

ソースのインポート

ソースコードをIDEAプロジェクトとしてインポートします。

  1. メニューを File>New>Project from Existing Source とたどります。
  2. ソースルートを選択
  3. Import project from external model
  4. SBTを選択
  5. Project SDK に Java8 を選択し Finish

以上で、Play+ScalaのスケルトンプロジェクトができてIDEAでの開発準備が整いました。