Scalaのplayframework2.0を使って開発することになったので、ローカルのWindows環境の構築手順をメモ。
- 下記URLから sbt-launch.jar をダウンロードします。
http://typesafe.artifactoryonline.com/typesafe/ivy-releases/org.scala-tools.sbt/sbt-launch/0.11.2/sbt-launch.jar
- 任意のディレクトリに sbt-launch.jar を置いて、同じディレクトリ内に下記の内容で sbt.bat を作成します。
1 set SCRIPT_DIR=%~dp0
2 java -Xmx512M -jar "%SCRIPT_DIR%sbt-launch.jar" %*
- 上記ディレクトリにパスを通し、sbt コマンドで起動します。
1 C:\Users\akanuma>sbt
2
3 C:\Users\akanuma>set SCRIPT_DIR=C:\sbt\
4
5 C:\Users\akanuma>java -Xmx512M -jar "C:\sbt\sbt-launch.jar"
6 Getting net.java.dev.jna jna 3.2.3 ...
7 downloading http://repo1.maven.org/maven2/net/java/dev/jna/jna/3.2.3/jna-3.2.3.jar ...
8 [SUCCESSFUL ] net.java.dev.jna
9 :: retrieving :: org.scala-tools.sbt
10 confs: [default]
11 1 artifacts copied, 0 already retrieved (838kB/106ms)
12 Getting Scala 2.9.1 (for sbt)...
13 ~~~ 中略 ~~~
14 [info] Resolving org.scala-tools.sbt
15 [info] Resolving org.scala-tools.sbt
16 [info] Resolving org.scala-tools.sbt
17 [info] Done updating.
18 [info] Set current project to default-83bb15 (in build file:/C:/Users/akanuma/)
19 >
- 下記サイトから play-2.0.zip をダウンロードします。
http://www.playframework.org/
- 任意の場所で解凍してパスを通し、playコマンドでインストールします。
1 C:\Users\akanuma>play
2 Getting net.java.dev.jna jna 3.2.3 ...
3 :: retrieving :: org.scala-tools.sbt
4 confs: [default]
5 1 artifacts copied, 0 already retrieved (838kB/510ms)
6 Getting Scala 2.9.1 (for console)...
7 :: retrieving :: org.scala-tools.sbt
8 confs: [default]
9 4 artifacts copied, 0 already retrieved (19939kB/3195ms)
10 Getting play console_2.9.1 2.0 ...
11 :: retrieving :: org.scala-tools.sbt
12 confs: [default]
13 4 artifacts copied, 0 already retrieved (1472kB/566ms)
14 _ _
15 _ __ | | __ _ _ _| |
16 | '_ \| |/ _' | || |_|
17 | __/|_|\____|\__ (_)
18 |_| |__/
19
20 play! 2.0, http://www.playframework.org
21
22 This is not a play application!
23
24 Use `play new` to create a new Play application in the current directory,
25 or go to an existing application and launch the development console using `play`.
26
27 You can also browse the complete documentation at http://www.playframework.org.
- アプリケーション用の任意のディレクトリで play new コマンドでアプリケーションを作成します。ここでは play_new_sample ディレクトリで sample という名前のアプリケーションを作成します。
1 C:\play_new_sample>play new sample
2 _ _
3 _ __ | | __ _ _ _| |
4 | '_ \| |/ _' | || |_|
5 | __/|_|\____|\__ (_)
6 |_| |__/
7
8 play! 2.0, http://www.playframework.org
9
10 The new application will be created in C:\play_new_sample\sample
11
12 What is the application name?
13 > sample
14
15 Which template do you want to use for this new application?
16
17 1 - Create a simple Scala application
18 2 - Create a simple Java application
19 3 - Create an empty project
20
21 > 1
22
23 OK, application sample is created.
24
25 Have fun!
- コマンドを実行したディレクトリにアプリケーション名のディレクトリが作成されますので、その中に移動して play run コマンドでアプリケーションを起動します。
1 C:\play_new_sample\sample>play run
2 Getting org.scala-tools.sbt sbt_2.9.1 0.11.2 ...
3 :: retrieving :: org.scala-tools.sbt
4 confs: [default]
5 37 artifacts copied, 0 already retrieved (7324kB/3942ms)
6 [info] Loading project definition from C:\play_new_sample\sample\project
7 [info] Set current project to sample (in build file:/C:/play_new_sample/sample/)
8
9 [info] Updating {file:/C:/play_new_sample/sample/}sample...
10 [info] Done updating.
11 --- (Running the application from SBT, auto-reloading is enabled) ---
12
13 [info] play - Listening for HTTP on port 9000...
14
15 (Server started, use Ctrl+D to stop and go back to the console...)
16
- ブラウザでlocalhostの9000番ポートにアクセスして起動を確認します。
1 C:\play_new_sample\sample>play eclipsify
2 [info] Loading project definition from C:\play_new_sample\sample\project
3 [info] Set current project to sample (in build file:/C:/play_new_sample/sample/)
4 [info] About to create Eclipse project files for your project(s).
5 [info] Successfully created Eclipse project files for project(s): sample
EclipseでScalaの開発をするためのプラグインとして、Scala IDE for Eclipse があります。Eclipse3.6(Helios)が正式サポート対象で、3.7(Indigo)では一部動作しない機能があります。
Eclipse の Helpメニュー > Install New Software から下記URL(Scala 2.9.x用)を指定してプラグインをインストールします。
http://download.scala-ide.org/releases-29/stable/site
- Scala2.8.xの場合は下記URLになります。
http://download.scala-ide.org/releases-28/stable/site
- これでひとまずアプリケーションの作成はできましたので、必要なロジックを作りこんでいくことになります。