Scala Applications

Jakob Jenkov
Last update: 2014-05-25

In order to run a Scala program using the scala command, you need to create a singleton object with a main(args: Array[String]) method, like this:

object Main {
    def main(args: Array[String]) {

      println("Main class! ... execution starts here.");


You don't have to call the singleton object Main. Just the method needs that name and signature (parameters).

The String arguments passed to the main() method are the command line arguments passed to the application when it is executed.

Running the Scala Application

Here is how you run the Scala application:

scala -classpath . Main  arg1 arg2

The Main argument is the name of the object to run the main() method of. In this case the object is called Main.

The arguments "arg1" and "arg2" are passed in the String array to the main() method. The application can do with them as it pleases.

You can find more information about how to run Scala applications on the Scala website.

Jakob Jenkov

Featured Videos


Java Persistence
Close TOC

All Trails

Trail TOC

Page TOC