星期二, 7月 14, 2015

CentOS 7 安裝 Sbt 小記

OS: CentOS 7 in Chameleon Cloud


要開發 scala 與 spark 好像要裝 sbt 或是另外一個軟體
所以我就先選擇 sbt 來進行開發環境


可以參考 在Linux上安裝 sbt 這段

首先先來觀察 官方的 repo 設定
$ curl    https://bintray.com/sbt/rpm/rpm
#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

接下來將他導成文字檔

$ curl   https://bintray.com/sbt/rpm/rpm  >   bintray-sbt-rpm.repo
 % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                Dload  Upload   Total   Spent    Left  Speed
100   146    0   146    0     0    454      0 --:--:-- --:--:-- --:--:--   456

觀察資訊
$ ls
bintray-sbt-rpm.repo  scala-2.10.1.tgz           spark-1.4.0-bin-hadoop2.6.tgz
Install.sh            spark-1.4.0-bin-hadoop2.6

透過 sudo 來把 repo設定檔案放到 系統 yum.repos.d 目錄下
$ sudo  mv  bintray-sbt-rpm.repo   /etc/yum.repos.d/

這個時候就搜尋的到 sbt 套件了
$ sudo  yum  search   sbt
base                                                                        | 3.6 kB  00:00:00     
bintray--sbt-rpm                                                            | 1.2 kB  00:00:00     
epel/x86_64/metalink                                                        |  12 kB  00:00:00     
extras                                                                      | 3.4 kB  00:00:00     
openstack-juno                                                              | 2.9 kB  00:00:00     
updates                                                                     | 3.4 kB  00:00:00     
bintray--sbt-rpm/primary                                                    | 1.6 kB  00:00:00     
bintray--sbt-rpm                                                                               9/9
======================================== N/S matched: sbt =========================================
libreport-plugin-mantisbt.x86_64 : libreport's mantisbt plugin
sbt.noarch : Simple Build Tool for Scala-driven builds

 Name and summary matches only, use "search all" for everything.

安裝 sbt
$ sudo  yum  install   sbt   -y
Resolving Dependencies
--> Running transaction check
---> Package sbt.noarch 0:0.13.8-1 will be installed
--> Finished Dependency Resolution

Dependencies Resolved

=========================================================================================
Package          Arch                Version                  Repository                     Size
=========================================================================================
Installing:
sbt              noarch              0.13.8-1                 bintray--sbt-rpm              1.0 M

Transaction Summary
=========================================================================================
Install  1 Package

Total download size: 1.0 M
Installed size: 1.2 M
Downloading packages:
sbt-0.13.8.rpm                                                              | 1.0 MB  00:00:01     
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
 Installing : sbt-0.13.8-1.noarch                                                             1/1
 Verifying  : sbt-0.13.8-1.noarch                                                             1/1

Installed:
 sbt.noarch 0:0.13.8-1                                                                            

Complete!


Hello, world 測試


$ mkdir hello
$ ls
hello  Install.sh  scala-2.10.1.tgz  spark-1.4.0-bin-hadoop2.6  spark-1.4.0-bin-hadoop2.6.tgz
$ cd  hello/
$ echo 'object Hi { def main(args: Array[String]) = println("Hi!") }' > hw.scala

$ cat hw.scala
object Hi { def main(args: Array[String]) = println("Hi!") }

$ sbt
Getting org.scala-sbt sbt 0.13.8 ...
downloading https://repo.typesafe.com/typesafe/ivy-releases/org.scala-sbt/compiler-interface/0.13.8/jars/compiler-interface-src.jar ...
Getting Scala 2.10.4 (for sbt)...
downloading https://repo1.maven.org/maven2/org/scala-lang/jline/2.10.4/jline-2.10.4.jar ...
[SUCCESSFUL ] org.scala-lang#jline;2.10.4!jline.jar (194ms)
downloading https://repo1.maven.org/maven2/org/fusesource/jansi/jansi/1.4/jansi-1.4.jar ...
[SUCCESSFUL ] org.fusesource.jansi#jansi;1.4!jansi.jar (159ms)
:: retrieving :: org.scala-sbt#boot-scala
confs: [default]
5 artifacts copied, 0 already retrieved (24459kB/42ms)
[info] Set current project to hello (in build file:/home/cc/hello/)

在界面下 執行
> run
[info] Updating {file:/home/cc/hello/}hello...
[info] Resolving org.fusesource.jansi#jansi;1.4 ...
[info] Done updating.
[info] Compiling 1 Scala source to /home/cc/hello/target/scala-2.10/classes...
[info] Running Hi
Hi!
[success] Total time: 3 s, completed 2015/7/13 下午 07:02:59
離開
> exit

按照上面的訊息,  產出到 target/scala-2.10/classes 目錄下
觀察資訊, 看到兩個  .class 檔案
$ ls   target/scala-2.10/classes/
Hi.class  Hi$.class

批次模式( 非互動 )
  • $sbt  compile
  • 這邊有注意到, 因為之前  build.sbt 設定的關係
  • 所以編出來的 scala 版本會依照 build.sbt 內的設定     

常用命令
  • clean
    • 刪除所有在 target 目錄下產生的文件
  • compile
    • 編譯 source code ( src/main/scala 與 src/main/java 目錄下 )
  • test
    • 編譯與執行所有測試
  • console
    • 進到 scala 互動界面
    • 打 :quit離開
  • run <參數>*
    • 執行 main class
  • package
    • 建立 jar 檔案
    • 根據 src/main/resources與 src/main/scala 及 src/main/java
  • help <命令>
  • reload
    • reload build.sbt, project/*.scala, project/*.sbt  



下次應該可以考慮 寫成  shell script 自動安裝
^^

~ enjoy it

沒有留言: