IT練習ノート

IT関連で調べたこと(実際は嵌ったこと)を書いています。

Play2の練習

Evolutionalなdb開発(<-日本語がよろしくない)に関心があり、とっかかりとしてPlay2をインストールしてみました。

ダウンロードします。

[play2]$ wget http://downloads.typesafe.com/play/2.2.3/play-2.2.3.zip
--2014-05-11 07:33:05--  http://downloads.typesafe.com/play/2.2.3/play-2.2.3.zip
downloads.typesafe.com をDNSに問いあわせています... 54.230.113.191, 54.230.113.192, 54.230.115.148, ...
downloads.typesafe.com|54.230.113.191|:80 に接続しています... 接続しました。
HTTP による接続要求を送信しました、応答を待っています... 200 OK
長さ: 112903404 (108M) [application/zip]
`play-2.2.3.zip' に保存中

100%[==================================================================================================================================================================>] 112,903,404 16.2M/s 時間 9.0s    

2014-05-11 07:33:14 (11.9 MB/s) - `play-2.2.3.zip' へ保存完了 [112903404/112903404]

scalaそのもののインストールはいらないようです。

解凍します。

[play2]$ unzip play-2.2.3.zip 
Archive:  play-2.2.3.zip
   creating: play-2.2.3/
  inflating: play-2.2.3/CONTRIBUTING.md  
   creating: play-2.2.3/framework/
  inflating: play-2.2.3/framework/build  
途中省略

実行権限をつけます。

[play2]$ ls
play-2.2.3  play-2.2.3.zip
[play2]$ ls play-2.2.3
CONTRIBUTING.md  README.md  framework  play  play.bat  repository  samples
[play2]$ cd play-2.2.3
CONTRIBUTING.md  README.md  framework  play  play.bat  repository  samples
[play-2.2.3]$ chmod a+x play
[play-2.2.3]$ chmod a+x framework/build

ヘルプを確認します。

[play-2.2.3]$ ./play help
Getting com.typesafe.play console_2.10 2.2.3 ...
:: retrieving :: org.scala-sbt#boot-app
    confs: [default]
    6 artifacts copied, 0 already retrieved (2012kB/72ms)
Getting Scala 2.10.3 (for console)...
:: retrieving :: org.scala-sbt#boot-scala
    confs: [default]
    5 artifacts copied, 0 already retrieved (24447kB/169ms)
       _
 _ __ | | __ _ _  _
| '_ \| |/ _' | || |
|  __/|_|\____|\__ /
|_|            |__/

play 2.2.3 built with Scala 2.10.3 (running Java 1.7.0_55), http://www.playframework.com
Welcome to Play 2.2.3!

These commands are available:
-----------------------------
license            Display licensing informations.
new [directory]    Create a new Play application in the specified directory.

You can also browse the complete documentation at http://www.playframework.com.

アプリケーションを作成します。

[play-2.2.3]$ ./play new MyFirstApp
       _
 _ __ | | __ _ _  _
| '_ \| |/ _' | || |
|  __/|_|\____|\__ /
|_|            |__/

play 2.2.3 built with Scala 2.10.3 (running Java 1.7.0_55), http://www.playframework.com

The new application will be created in /home/user/play2/play-2.2.3/MyFirstApp

What is the application name? [MyFirstApp]
> FooApplication

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

  1             - Create a simple Scala application
  2             - Create a simple Java application

> 1
OK, application FooApplication is created.

Have fun!

[play-2.2.3]$ ls
CONTRIBUTING.md  MyFirstApp  README.md  framework  play  play.bat  repository  samples

実行します。

[play-2.2.3]$ cd MyFirstApp/
[MyFirstApp]$ ls
[MyFirstApp]$ /home/user/play2/play-2.2.3/play run
[info] Loading project definition from /home/user/play2/play-2.2.3/MyFirstApp/project
[info] Set current project to FooApplication (in build file:/home/user/play2/play-2.2.3/MyFirstApp/)
[info] Updating {file:/home/user/play2/play-2.2.3/MyFirstApp/}myfirstapp...
[info] Resolving org.fusesource.jansi#jansi;1.4 ...
[info] Done updating.

--- (Running the application from SBT, auto-reloading is enabled) ---

[info] play - Listening for HTTP on /0:0:0:0:0:0:0:0:9000

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

[info] Compiling 5 Scala sources and 1 Java source to /home/user/play2/play-2.2.3/MyFirstApp/target/scala-2.10/classes...
[info] 'compiler-interface' not yet compiled for Scala 2.10.3. Compiling...
[info]   Compilation completed in 47.654 s
[info] play - Application started (Dev)

最初はコンパイルに時間がかかります。 ポートは9000番です。

f:id:naotoogawa:20140511215111p:plain

デフォルトは下記パスにリソースがおかれるようです。routesファイルをみるとわかります。

f:id:naotoogawa:20140511214149p:plain

コードを変更して再アクセスすると再コンパイルされます。

[info] Compiling 5 Scala sources and 1 Java source to /home/user/play2/play-2.2.3/MyFirstApp/target/scala-2.10/classes...
[info] 'compiler-interface' not yet compiled for Scala 2.10.3. Compiling...
[info]   Compilation completed in 47.654 s
[info] play - Application started (Dev)
[info] Compiling 1 Scala source to /home/user/play2/play-2.2.3/MyFirstApp/target/scala-2.10/classes...

--- (RELOAD) ---

[info] play - Application started (Dev)

f:id:naotoogawa:20140511214037p:plain

エラーの場合はコードの場所を示します。

(本番環境ではoffにすると思いますが、設定はどこにあるのだろう??)

f:id:naotoogawa:20140511214131p:plain