Coding With Fun
Home Docker Django Node.js Articles Python pip guide FAQ Policy

How to compile scala code with scalac and run it with scala?


Asked by Lilianna Patrick on Dec 11, 2021 Scala



This is Recipe 14.5, “How to compile Scala code with scalac and run it with scala .” Though you normally use the Simple Build Tool (SBT) to build Scala applications, you may want to use more basic tools to compile and run small test programs, in the same way you might use javac and java with small Java applications.
Subsequently,
Scala compiler scalac offers various compiler options, also referred to as compiler flags, to change how to compile your program. Nowadays, most people are not running scalac from the command line. Instead, they use sbt, an IDE, and other tools as their interface to the compiler.
In fact, Nowadays, most people are not running scalac from the command line. Instead, they use sbt, an IDE, and other tools as their interface to the compiler. Therefore they may not even have scalac installed, and won’t think to do man scalac. This page comes to the rescue for the people to find… Default paths can be listed by running a command line tool:
Next,
Running Scala Binaries. To run Scala from the command-line, simply download the binaries and unpack the archive. Start the Scala interpreter (aka the “REPL”) by launching scala from where it was unarchived. Start the Scala compiler by launching scalac from where it was unarchived.
Thereof,
Run a Scala application using the sbt shell. You can run your application using the sbt shell that is a part of any sbt project. Open your sbt project. If you want to delegate your builds and imports to sbt, in the sbt projects tool window, click the icon to open the sbt settings.