You can start to learn Scala from the official tutorial. A good Chinese page to learn Scala is here.
sbt is a build tool for Scala (and also for Java). You can write scala code with out install scala on your system with the help of SBT (But you have to have Java installed).
Install SBT
For Debian:
echo "deb https://dl.bintray.com/sbt/debian /" | sudo tee -a /etc/apt/sources.list.d/sbt.list
sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv 642AC823
sudo apt-get update
sudo apt-get install sbt
build.sbt
name := "sbt-sample"
version := "0.1.0"
scalaVersion := "2.11.6"
organization := "org.janzhou"
Hello World
Create hello-world.scala
:
package org.janzhou.hello-world
object hello-world {
def main (args: Array[String]) {
println("Hello, world!")
}
}
Compile
sbt compile
sbt run
Package
Create jar by using command:
sbt package
The jar is located at target/scala-2.11/hello-world_2.11-0.1.0.jar
. You can run it by using scala-2.11.
assembly plugin
If you want a big jar which can run with out scala, need to use assembly plugin. Add file project/assembly.sbt
:
addSbtPlugin("com.eed3si9n" % "sbt-assembly" % "0.13.0")
Run command:
sbt assembly
The jar is located at target/scala-2.11/hello-world-assembly-0.1.0.jar
.