LoginSignup
16
16

More than 5 years have passed since last update.

scala環境構築(Mac)

Last updated at Posted at 2014-04-18

Scala 初めての人が Heroku で Web アプリを公開するまで
ここを参考にしてScalaをインストールしてPlay FrameworkというWebアプリケーションフレームワークを動かしてみようと思います。

Svmのインストール

https://github.com/yuroyoro/svm.git
Scalaのバージョンを簡単に切り替えられる"svm"ってヤツ作った (冷やし中華終わりました)

rubyで言うところのrvmみたいにScalaのversionを切り替えたり出来たりするtoolみたいです。
あると便利そうなのでインストールします。

ホームディレクトリにbinフォルダを作成し、そこにパスを通してsvmの実行ファイルのリンクを貼ります。

$ mkdir ~/.svm
$ git clone https://github.com/yuroyoro/svm.git ~/.svm/svm
$ mkdir  ~/bin
$ echo 'export PATH=$PATH:$HOME/bin' >> ~/.bash_profile 
$ echo 'export SCALA_HOME=~/.svm/current/rt' >> ~/.bash_profile 
$ echo 'export PATH=$SCALA_HOME/bin:$PATH' >> ~/.bash_profile 
$ source ~/.bash_profile 
$ ln -s ~/.svm/svm/svm  ~/bin/svm
$ svm install 2.10.4

$ scala -help
Picked up _JAVA_OPTIONS: -Dfile.encoding=UTF-8
Usage: scala <options> [<script|class|object|jar> <arguments>]
   or  scala -help

All options to scalac (see scalac -help) are also allowed.
The first given argument other than options to scala designates
what to run.  Runnable targets are:

  - a file containing scala source
  - the name of a compiled class
  - a runnable jar file with a valid Main-Class attribute
  - or if no argument is given, the repl (interactive shell) is started

Options to scala which reach the java runtime:

 -Dname=prop  passed directly to java to set system properties
 -J<arg>      -J is stripped and <arg> passed to java as-is
 -nobootcp    do not put the scala jars on the boot classpath (slower)

Other startup options:

 -howtorun    what to run <script|object|jar|guess> (default: guess)
 -i <file>    preload <file> before starting the repl
 -e <string>  execute <string> as if entered in the repl
 -save        save the compiled script in a jar for future use
 -nc          no compilation daemon: do not use the fsc offline compiler

A file argument will be run as a scala script unless it contains only
self-contained compilation units (classes and objects) and exactly one
runnable main method.  In that case the file will be compiled and the
main method invoked.  This provides a bridge between scripts and standard
scala source.


Options for plugin 'continuations':
  -P:continuations:enable        Enable continuations

Play Frameworkのインストール

$ brew install play
$ play new firstplay
Picked up _JAVA_OPTIONS: -Dfile.encoding=UTF-8
       _
 _ __ | | __ _ _  _
| '_ \| |/ _' | || |
|  __/|_|\____|\__ /
|_|            |__/

play 2.2.2 built with Scala 2.10.3 (running Java 1.6.0_65), http://www.playframework.com

The new application will be created in /Users/daichi/Documents/0_projects/scala/firstplay

What is the application name? [firstplay]
> 

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

Have fun!

$ cd firstplay
$ play run
Picked up _JAVA_OPTIONS: -Dfile.encoding=UTF-8
Getting org.scala-sbt sbt 0.13.0 ...
:: retrieving :: org.scala-sbt#boot-app
    confs: [default]
    43 artifacts copied, 0 already retrieved (12440kB/1005ms)
[info] Loading project definition from /Users/daichi/Documents/0_projects/scala/firstplay/project
[info] Set current project to firstplay (in build file:/Users/daichi/Documents/0_projects/scala/firstplay/)
[info] Updating {file:/Users/daichi/Documents/0_projects/scala/firstplay/}firstplay...
[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%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 /Users/daichi/Documents/0_projects/scala/firstplay/target/scala-2.10/classes...
[info] 'compiler-interface' not yet compiled for Scala 2.10.3. Compiling...
[info]   Compilation completed in 19.852 s
[info] play - Application started (Dev)

pray runをやると http://0.0.0.0:9000/
でデフォルト画面にアクセスできます。

スクリーンショット 2014-04-18 11.09.17.png

16
16
0

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
16
16