Sunday, March 4, 2012

Creating a new project and its definition in SBT - Ubuntu 11.10

Credit goes to the original publishers...
I modified or organized the original content...
Before creating a new project the sbt  should be setup to launch it from any directory. To do it follow the [2-5] for Ubuntu 11.10



1. Choose your own directory to create a new project
2. Using Terminal, enter into the directory where you planned to create a new project
3. Type sbt into the terminal, if the sbt launch is set properly, you see the below image content



4.It will ask you, create a new project? (y/N/s)  Type y and press enter

5. The project has been successfully created, you can check it by visiting the directory where you created the new project, You could see the four folders as shown in the right side of the top image.

6. let us start with an example code, to test if our new project works fine. Copy the below code to the directory  src\main\scala

   object Anil{
         def main(args:Array[String]){
           println("\n\n Hello Anil, You program has been successfully Executed \n\n ")
         } 
    }





7. From Terminal go to directory
8. Type sbt and press enter.
9. Type reload and press enter.
10.Type update and press enter.
11. Type run and press enter.
If everything goes fine you could see the output displayed in blow image 


12. Configure sbt by creating project definition using a scala file in to the directory  project\build\MyFirstProject.scala

import sbt._
class AnilsProject(info: ProjectInfo) extends DefaultProject(info) {
lazy val hi=task {println("This is Anils First New Project"); None}
}





13. Type hi in command prompt, you will see...



By now, You know how to create a new project, configure SBT by creating a project definition, program an example in Scala and successfully execute it.
Good Luck with the rest.
enjoy the rest of your journey with Scala using SBT

No comments:

Post a Comment