请勿进行商业转载,学习交流转载请注明出处
- Download Scala (http://www.scala-lang.org/download/)
- Java Runtime (1.6 or Above)
- 设置好SCALA_HOME和PATH
- IDE: Scala-IDE(Eclipse) / IntelliJ + Scala Plugin
- 编译&运行
1.scala:
object HelloWorld {
def main(args: Array[String]) {
println("Hello, world!")
}
}
hcheng@chenghao:~/home/hcheng/scalac 1.scala
hcheng@chenghao:~/home/hcheng/scala HelloWorld
- 在Scala Shell中执行
hcheng@chenghao:~/SCALA_HOME/bin/scala
scala>println("Hello, world!")
Hello, world!
scala>
- 当作普通脚本运行
2.scala:
println("Hello, world!")
$/tmp>scala 2.scala
Hello, world!
- 当作Shell脚本运行
file: script.sh
#!/bin/sh
exec scala "$0" "$@"
!#
object HelloWorld {
def main(args: Array[String]) {
println("Hello, world! " + args.toList)
}
}
HelloWorld.main(args)
$/tmp>chmod +x script.sh
$/tmp>./script.sh
Hello, world!