Build your first scala project with sbt

In this article, We are going to create new Scala project with standard project structure and Simple program to print Hello Scala!. Later, We will build and run the project with sbt(Scala Build Tool). sbt is build tool similar to Maven and Gradle.

Scala Project structure with sbt will be like this:

src/  
  main/
    resources/
    scala/
    java/
  test/
    resources
    scala/
    java/
build.sbt  
build.properties  


First install sbt in your system. Follow sbt setup instruction from sbt documentation.
Once you setup sbt successfully, create following files

build.properties file into your project root directory with the following content.

# sbt version
sbt.version=0.13.9  


build.sbt file into your project root directory with the following content.

lazy val root = (project in file(".")).  
  settings(
    name := "Hello-Scala", // Project Name
    version := "0.1.0",  // Project version
    scalaVersion := "2.11.7" // Scala version
  )


Hello.scala file into the src/main/scala directory with following content.

object Hello {  
  def main (args: Array[String]):Unit = {
    println("Hello Scala!")
  }
}

This is simple program to print Hello Scala!.

That's it :)
Now time to run the Project.
Execute sbt run command into the project root directory to run the project.
To compile the project you can run sbt compile

You can get this code at GitHub repository Scala-Experiments.
https://github.com/pgkaila/Scala-Experiments

For more details about sbt please read sbt documentation. Or Comment If any query. I would like to help you.

This is my first article on this blog on Scala. I'm reading the book Scala In Depth to learn scala. and also some online articles.

Comments

comments powered by Disqus