LoginSignup
9

More than 5 years have passed since last update.

Scala+Playの導入が簡単だという話

Last updated at Posted at 2013-01-30

OSはMacOS Xです。

なんぞ簡単だったのでご紹介します。
結論からいうと、brewでインストールします。

brewで確認してみると、

% brew search scala
scala
% brew search sbt      
sbt
% brew search play     
play

ちゃんと入っています。(上記のコマンドの出力結果はわかりやすく要らないものを削っています)

なので、

% brew install scala
% brew install sbt      
% brew install play  

とするだけでOK。

インストールが終わったら、適当なディレクトリを作ります。

% mkdir ./Projects/Scala/play_work
% cd ./Projects/Scala/play_work

移動したら、次のコマンドを使ってサンプルプロジェクトを生成してみましょう。

% play new prac1

実行すると、アプリケーションの名前を聞かれます。適当にエンターキーでいいと思います。

       _            _ 
 _ __ | | __ _ _  _| |
| '_ \| |/ _' | || |_|
|  __/|_|\____|\__ (_)
|_|            |__/ 

play! 2.0.4, http://www.playframework.org

The new application will be created in ./play_work/prac2

What is the application name? 
> prac2

次に、テンプレートの選択です。ここでは1を選択しましょう。

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 prac2 is created.

Have fun!

Playのrunコマンドを使って開発モードで実行しましょう

% cd ./prac2
% play run
[info] Loading project definition from ./play_work/prac2/project
[info] Set current project to prac2 (in build file:./play_work/prac2/)

[info] Updating {file:./play_work/prac2/}prac2...
[info] Done updating.                                                                  
--- (Running the application from SBT, auto-reloading is enabled) ---

[info] play - Listening for HTTP on port 9000...

(Server started, use Ctrl+D to stop and go back to the console...)

ブラウザでLocalhostの9000ポートにアクセスすると次の画面が出ます。

Play起動画面

以上までが導入でした。

なお、本番用に実行する場合は、startコマンドを使用します。

テンプレートでstartコマンドで起動すると、Viewが切り替わって以下の様になります。
Startでの起動画面

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
9