Play framework 2.0 betaが出たようです1 – インストール

2011.11.06

この記事は公開されてから1年以上経過しています。情報が古い可能性がありますので、ご注意ください。

Play framework 2.0 betaリリース

先日Play 2.0のGithubをみると、大幅な更新がありました。 Wikiやドキュメントも大きく更新されており、来年のリリースへむけて大きく進んだことがわかります。
今回はGithubからのダウンロードからサンプルを動かすところまでやってみましょう。
なお、使用した動作環境は以下のとおりです。

  • OS : MacOS X 10.7.2

ダウンロードとインストール

では、Githubから最新のソースをダウンロードしましょう。
GithubではPlay 2.0 betaのバイナリへのリンクもあるのですが、現時点では404エラーがでてダウンロードできません。
ここからダウンロードできるならそれを使用してもかまいません。
ではGithubからPlay 2.0のソースをcloneし、ビルドします。

% git clone git://github.com/playframework/Play20.git
% cd Play20/framework
% ./build
・・・
> build-repository

frameworkディレクトリに移動し、buildを実行します。その後build-repositoryコマンドを実行して準備完了です。

初回はjarのダウンロードなどで少々時間がかかります。ビルドができたら早速プロジェクトを作成してみましょう。
今回のサンプルコードではplayコマンドシェルへの相対パスで指定していますが、PATH環境変数を設定していれば相対パスの必要はありません。

%../play new firstSample                                        
Picked up _JAVA_OPTIONS: -Dfile.encoding=UTF-8
       _            _ 
 _ __ | | __ _ _  _| |
| '_ \| |/ _' | || |_|
|  __/|_|\____|\__ (_)
|_|            |__/ 
             
play! 2.0-beta, http://www.playframework.org

The new application will be created in /Users/path/Play20/samples/firstSample

What is the application name? 
> firstSample

Which template do you want to use for this new application? 

  1 - Create a simple Scala application
  2 - Create a simple Java application
  3 - Create an empty project

> 1

OK, application firstSample is created.
Type `play` to enter the development console.
Have fun!

いままでと違い、play newコマンドを実行すると、プロジェクトの雛形をScalaベース/Javaベース/空プロジェクトから選択できます。
今回はプロジェクト名をfirstSampleとし、1を入力してScalaベースにしました。

%cd firstSample/
%../../play     
Picked up _JAVA_OPTIONS: -Dfile.encoding=UTF-8
[info] Loading project definition from /Users/Play20/samples/firstSample/project
[info] Updating {file:/Users/Play20/samples/firstSample/project/}default-921df2...
[info] Done updating.
[info] Compiling 1 Scala source to /Users/Play20/samples/firstSample/project/target/scala-2.9.1/sbt-0.11.0/classes...
[info] Set current project to firstSample (in build file:/Users/Play20/samples/firstSample/)
       _            _ 
 _ __ | | __ _ _  _| |
| '_ \| |/ _' | || |_|
|  __/|_|\____|\__ (_)
|_|            |__/ 
             
play! 2.0-beta, http://www.playframework.org

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

[firstSample] $

firstSampleディレクトリに移動して、playコマンドを実行してsbtを起動します。
sbt上でrunと入力すると、firstSampleプロジェクトが起動します。localhost:9000にアクセスしてみてください。

[firstSample] $ run

なお、sbtコンソール上でconsoleと入力すると、ScalaのREPLが起動し、直接Scalaコードを対話的に実行することができます。

まとめ

今回は駆け足でインストールからサンプル起動までやってみました。
次回もPlay 2.0betaについていろいろと動かしてみます。

参考サイトなど

  • ※1 https://github.com/playframework/Play20/wiki/Installing