Scala

51 / 53

Scala - Build Tool - SBT




Not able to play video? Try with youtube

* Video Transcript:*

So far, we have just compiled and run one .scala file. If we are working on a big project containing hundreds of source files, it becomes really tedious to compile these files manually. We'll then need a build tool to manage the compilation of all these files. SBT is a build tool for Scala and Java projects, similar to Java's Maven or ant. SBT is already installed on CloudxLab so you can compile your Scala project directly on it.

Let's understand how to use SBT to build a Scala project. We've provided a sample code on the CloudxLab GitHub repository. Clone the CloudxLab GitHub repository in your home folder in CloudxLab.

This will create a cloudxlab folder in your home directory. Now, Go to that directory cloudxlab. To update a previously cloned repository you can use run command 'git pull origin master'

Since I have already cloned the repository, I will just update it. Go to scala/sbt directory. Let's look at the build.sbt file.

build.sbt file lists all the source files your project consists of, along with other information about your project. SBT will read the file to understand what to do to compile the entire project.

Besides managing the project, SBT automatically manages dependencies. This means that if we need to use some libraries written by others in our project, SBT can automatically download the right versions of those libraries and include them in the project.

As you can see, the name of our project is hello, version of the project is 1.0 and the Scala version required for the project is 2.11.8. We do not have any dependencies here. We'll show you how to include dependencies in the Spark streaming topic.

Also, please note that all the Scala files must be in the src/main/scala directory. You can see that we have hello_world.scala file inside the src/main/scala directory.

Let's run the project. Type "sbt run" from the root of your project. It will run the main class of the project. Hello, world! is now printed on the screen.


Loading comments...