In this blog post, We will know how to debug application via sbt console. Suppose we want to do some initialization process before debugging the application. For example, database connection, importing packages etc. sbt configuration provide a nice way to make debug process easier.
There are some steps to debug Liftweb application via sbt console. First we have to initialize the database connection or initialize application before debugging. For that we have to run class Boot’s function boot.
Welcome to Scala version 2.10.3 (Java HotSpot(TM) 64-Bit Server VM, Java 1.7.0_51). Type in expressions to have them evaluated. Type :help for more information. scala> import bootstrap.liftweb.Boot import bootstrap.liftweb.Boot scala> new Boot().boot INFO - MongoDB inited: localhost/127.0.0.1:27017/typesafe scala> import code.model._ import code.model._ scala> import com.foursquare.rogue.LiftRogue._ import com.foursquare.rogue.LiftRogue._ scala> val score = Score.createRecord.examtype("homework").score(83.5) score: code.model.Score = class code.model.Score={examtype=homework, score=83.5} scala> val student = StudentInfo("Devid",List(score)) student: code.model.StudentInfo = StudentInfo(Devid,List(class code.model.Score={examtype=homework, score=83.5})) scala> Student.createBy(student) res3: code.model.Student = class code.model.Student={name=Devid, age=0, _id=53f04f2688e0d70d73c0fb50, scores=List(class code.model.Score={examtype=homework, score=83.5}), address=} scala> Student.where(_.name eqs "Devid").fetch res4: List[code.model.Student] = List(class code.model.Student={name=Devid, age=0, _id=53f04f2688e0d70d73c0fb50, scores=List(class code.model.Score={examtype=homework, score=83.5}), address=}) scala>
Now we don’t want to import packages or database connection initialization manually so sbt configuration setting Define the initial commands evaluated when entering the Scala REPL. Just define initial commands in build.sbt
initialCommands in console := """ import bootstrap.liftweb._ import code.model._ import org.bson.types.ObjectId import net.liftweb.common._ import com.foursquare.rogue.LiftRogue._ new.Boot().boot """
now again run the REPL:
abdhesh@abdhesh-Vostro-3560:~/Documents/projects/knoldus/Rogue_Query$ sbt console [info] Loading project definition from /home/abdhesh/Documents/projects/knoldus/Rogue_Query/project [info] Set current project to Rogue_Query (in build file:/home/abdhesh/Documents/projects/knoldus/Rogue_Query/) [info] Starting scala interpreter... [info] INFO - MongoDB inited: localhost/127.0.0.1:27017/typesafe import bootstrap.liftweb._ import code.model._ import org.bson.types.ObjectId import net.liftweb.common._ import com.foursquare.rogue.LiftRogue._ Welcome to Scala version 2.10.3 (Java HotSpot(TM) 64-Bit Server VM, Java 1.7.0_51). Type in expressions to have them evaluated. Type :help for more information. scala> val score = Score.createRecord.examtype("homework").score(83.5) score: code.model.Score = class code.model.Score={examtype=homework, score=83.5} scala> val student = StudentInfo("Devid",List(score)) student: code.model.StudentInfo = StudentInfo(Devid,List(class code.model.Score={examtype=homework, score=83.5})) scala> Student.createBy(student) res3: code.model.Student = class code.model.Student={name=Devid, age=0, _id=53f04f2688e0d70d73c0fb50, scores=List(class code.model.Score={examtype=homework, score=83.5}), address=} scala> Student.where(_.name eqs "Devid").fetch res4: List[code.model.Student] = List(class code.model.Student={name=Devid, age=0, _id=53f04f2688e0d70d73c0fb50, scores=List(class code.model.Score={examtype=homework, score=83.5}), address=})
Now There is no need to run initialization process manually once you define initialCommands in build.sbt.