Monday, September 9, 2013

How to run scala as script

1. Through interpreter
$ cat script.scala
println("Hello, World!")

Run:
scala script.scala

2. Thought a Scala script

$ cat script.scala
#!/usr/bin/scala!#
println("Hello, World!")

Run as:
$ ./script.scala

3. Compile and then run compiled class
, source.

$ cat script.scala
object Greeting {
    def main(args: Array[String]) = println("Hello world!")
}

Run as:
$ scalac script.scala
$ scala Greeting


Happy scripting!

No comments:

Post a Comment