LinuxCommandLibrary

scala

Run the Scala compiler and REPL

TLDR

Start a REPL (interactive shell)

$ scala
copy

Start the interpreter with a dependency in the classpath
$ scala -classpath [filename.jar] [command]
copy

Execute a Scala script
$ scala [script.scala]
copy

Execute a .jar program
$ scala [filename.jar]
copy

Execute a single Scala command in the command-line
$ scala -e [command]
copy

SYNOPSIS

scala [ options ] [ script file | arguments ]

PARAMETERS

options
    Various command-line options controlling the Scala compiler or interpreter's behavior. These include options for setting the classpath, specifying compiler flags, and managing memory allocation.

script file
    The path to a Scala script file to be executed by the interpreter. When a script file is provided, the interpreter executes the code within it.

arguments
    Arguments passed to the Scala program if a script file is being run. These can be accessed within the Scala program as an array of strings.

DESCRIPTION

The `scala` command is a versatile tool used to launch the Scala interpreter (REPL - Read-Eval-Print Loop) or to compile Scala source code. When invoked without arguments, it starts the interactive interpreter. When given `.scala` files as arguments, it acts as a compiler, producing `.class` files. The Scala REPL provides an environment where you can experiment with Scala code, test snippets, and explore the language's features interactively.

The compiler facilitates the creation of executable applications from Scala source code. It's an integral part of the Scala development workflow, allowing developers to build robust and scalable software.

CAVEATS

The specific available options and behavior might vary slightly depending on the Scala version installed on your system. It's crucial to consult the official Scala documentation for the version you're using for the most accurate and complete information.

CLASSPATH MANAGEMENT

The classpath is crucial for resolving dependencies. Use the `-classpath` or `-cp` options to specify directories or JAR files containing the necessary classes for your Scala code to run. Proper classpath configuration is essential to avoid `ClassNotFoundException` errors.

COMPILER OPTIONS

The Scala compiler offers a rich set of options that can be used to control compilation behavior, such as optimization levels, warning levels, and code generation settings. Explore compiler options to improve code quality and performance.

HISTORY

Scala was created by Martin Odersky at EPFL, first released in 2004. The `scala` command has evolved along with the language, becoming a core tool for development, scripting and interactive experimentation. Its design reflects the functional and object-oriented paradigms that Scala embraces.

SEE ALSO

scalac(1)

Copied to clipboard