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 ... |
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access