Scala on the Command Line

The scala command can run in two modes, as an interactive shell or in batch mode. If we don’t provide any arguments, as we saw, the command brings up the interactive shell. However, if we provide a filename then it runs the code in it within a stand-alone JVM.

The file we provide may be a script file or an object file—that is, a compiler-generated .class file. By default, we can let the tool guess the type of the given files. Alternately, use the -howtorun option to tell it to treat the file as a script file or as an object file. Finally, to send Java properties, use the -Dproperty=value format. Let’s create a file and run it using the command.

Here’s a file named HelloWorld.scala with the following contents:

FirstStep/HelloWorld.scala ...

Get Pragmatic Scala now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.