Saturday, March 3, 2012

Creating a new project and its definition in SBT - Windows 7

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 Windows 7



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

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 folder that you can see in the below image.
6. let us start with an example code, to test if our new project works fine. Copy the below code to the directory (In my case) C:\Users\anil\anil\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 command prompt go to directory (In my case) c:\Users\anil\anil
8. Type sbt and press enter.
9. Type relosd 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 (In my case) c:\Users\anil\anil\project\build\AnilFirstProject.scala

import sbt._
class HelloAnilProject(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