はじめてのScala

  • 投稿日:
  • by

自宅サーバーでScalaのコンパイルと実行ができるようにしてみた。

環境:CentOS

●まずはじめにSBTのインストール
[taka@centos6 ~]$ curl https://bintray.com/sbt/rpm/rpm | sudo tee /etc/yum.repos.d/bintray-sbt-rpm.repo
[sudo] password for taka:
#bintray--sbt-rpm - packages by  from Bintray
[bintray--sbt-rpm]
name=bintray--sbt-rpm
baseurl=http://dl.bintray.com/sbt/rpm
gpgcheck=0
enabled=1

sbt用のリポジトリの設定が済んだら次はRPMのインストールです

[taka@centos6 ~]$ sudo yum install sbt
======================================================================================================================
 Package                           Arch            Version                            Repository                 Size
======================================================================================================================
Installing:
 libjpeg-turbo                     i686            1.2.1-3.el6_5                      base                      177 k
     replacing  libjpeg.i686 6b-46.el6
 libjpeg-turbo-devel               i686            1.2.1-3.el6_5                      base                       96 k
     replacing  libjpeg-devel.i686 6b-46.el6
 sbt                               noarch          0.13.8-1                           bintray--sbt-rpm          1.0 M
Installing for dependencies:
 java-1.6.0-openjdk-devel          i686            1:1.6.0.35-1.13.7.1.el6_6          updates                    15 M
Updating for dependencies:
 java-1.6.0-openjdk                i686            1:1.6.0.35-1.13.7.1.el6_6          updates                    42 M

Transaction Summary
======================================================================================================================
Install       4 Package(s)
Upgrade       1 Package(s)

Total download size: 58 M
Is this ok [y/N]: y
Downloading Packages:
(1/5): java-1.6.0-openjdk-1.6.0.35-1.13.7.1.el6_6.i686.rpm                                     |  42 MB     00:17     
(2/5): java-1.6.0-openjdk-devel-1.6.0.35-1.13.7.1.el6_6.i686.rpm            

sbtのインストールが終わったら次はソースファイルの作成です。

●ソースファイルの作成
[taka@centos6 ~]$  mkdir -p prog/scala/hello
[taka@centos6 ~]$  cd prog/scala/hello/
[taka@centos6 ~]$ vi hw.scala

とりあえず、sbtのサイトに載ってるのをパクッって・・・

object Hi {
  def main(args: Array[String]) = println("Hi!")
}

●コンパイルと実行
初回はいろいろダウンロードされるようなので時間がかかるようです(3分くらい?

[taka@centos6 hello]$ sbt
Getting org.scala-sbt sbt 0.13.8 ...
downloading https://repo.typesafe.com/typesafe/ivy-releases/org.scala-sbt/sbt/0.13.8/jars/sbt.jar ...
        [SUCCESSFUL ] org.scala-sbt#sbt;0.13.8!sbt.jar (3770ms)
downloading https://repo1.maven.org/maven2/org/scala-lang/scala-library/2.10.4/scala-library-2.10.4.jar ...
        [SUCCESSFUL ] org.scala-lang#scala-library;2.10.4!scala-library.jar (29436ms)
downloading https://repo.typesafe.com/typesafe/ivy-releases/org.scala-sbt/main/0.13.8/jars/main.jar ...
        [SUCCESSFUL ] org.scala-sbt#main;0.13.8!main.jar (7231ms)
downloading https://repo.typesafe.com/typesafe/ivy-releases/org.scala-sbt/compiler-interface/0.13.8/jars/compiler-interface-src.jar ...

ダウンロードが終わるとコマンドの入力プロンプトが表示されますので「run」と入力します。

[info] Set current project to hello (in build file:/home/taka/prog/scala/hello/)
> run
[info] Updating {file:/home/taka/prog/scala/hello/}hello...
[info] Resolving org.fusesource.jansi#jansi;1.4 ...
[info] Done updating.
[info] Compiling 1 Scala source to /home/taka/prog/scala/hello/target/scala-2.10/classes...
[info] Running Hi
Hi!
[success] Total time: 16 s, completed 2015/05/06 15:13:31
>

たぶんCtrl+Cで終了すればいい

●ディレクトリ構造
勝手にいろいろディレクトリが作成されるみたいです

[taka@centos6 hello]$ ll
合計 8
-rw-rw-r-- 1 taka taka   64  5月  6 15:22 2015 hw.scala
drwxrwxr-x 5 taka taka 4096  5月  6 15:21 2015 target
[taka@centos6 hello]$ ll target/
合計 12
drwxrwxr-x 4 taka taka 4096  5月  6 15:21 2015 resolution-cache
drwxrwxr-x 3 taka taka 4096  5月  6 15:23 2015 scala-2.10
drwxrwxr-x 5 taka taka 4096  5月  6 15:21 2015 streams

今日はここまで。