Writing your first Scala Project in Windows

Rushali Sarkar
4 min readNov 23, 2021

I love to explore different languages (computer languages to be specific) and in my journey to do so, Scala is a milestone. But, whoosh! installing it and running it successfully on my machine was definitely a task. I am not talking about the Scala REPL but setting up an interactive build tool for Scala like SBT.

STEP 1

We will be using coursier to prepare the environment. There are two options for this, either you can download the windows installer from here, or you can open the command prompt and type the following command,

>bitsadmin /transfer cs-cli https://git.io/coursier-cli-windows-exe “%cd%cs.exe”

This will install all the standard Scala applications.

This is the coursier windows installer
Coursier Windows Installer
Typing in the command in the Command Prompt also does the job.

STEP 2

Next is setting up the IDE. You can use IntelliJ and install the Scala plugins but I will be using VS Code and the Powershell to execute my files.

Since I will be just using PowerShell to execute the files, there is no need to set up VS Code for running the programs. However, if you are going to use IntelliJ I recommend you to read how to install IntelliJ and the Scala plugin.

STEP 3

Next, you have to install Java Development Environment. I recommend you download the installer from Adopt Open JDK.

STEP 4

Next, do not forget to add the java development kit to your environment variables. For this, go to,

Edit Environment Variable -> Path -> New -> "Add the path to jdk folder"
Click onPath

STEP 5

Now is the time to install the sbt. Download the Windows installer from here. In case you want to use any third-party installation package like Chocolatey, you can see it in the documentation.

STEP 6

Having installed everything now is the time to check if everything is working fine and is installed. So, open your PowerShell and check if java, scala, and sbt all are installed properly in your system. For this run the following commands one after the other,

> java --version
> scala --version
> sdt --version

STEP 7

Once it's ensured that everything is up, installed, and working properly, now is the time we get into making our very first project.

For the sake of the same, I have created a folder Scala in D Drive and will be making my project in it. You can make it anywhere you want to. Now once inside the Scala folder, I am creating a folder HelloWorld to create my first project. The command would be,

> mkdir HelloWorld
> cd HelloWorld

STEP 8

Now, inside the HelloWorld folder start the sbt-shell. This will also install any required files for the project.

> sbt

Select c (for continue) when the command prompts to and you will end up in the sbt-shell.

STEP 9

Now, You have to create two files. One is build.sbt which will be inside the HelloWorld directory. This is our build file. Next is HelloWorld.scala which will be inside HelloWorld/src/scala/example folder. This is the file where we are going to write our first program. The directory listing will be something like this,

STEP 10

Once that’s done it’s time to create our first progam. In the HelloWorld.scala file write the following lines of code,

STEP 11

Finally, we are done with the steps. Now save your file and come back to PowerShell. In the sbt-shell we opened, type,

> compile
> run

And, there is the output!

That’s it! I have taken references from the SBT Reference Manual to write my first Scala program.

--

--