Product Catalog Application using Play and Scala Part 2 – Introduction to Play Framework commands
Wed, Jul 16, 2014
In this article we will be looking at some common commands we will be using when developing apps in Play Framework.
run – to run the web server, like we did in the previous article. The server will be launched with auto reload function, which means that if we changed our code the server will recompile and reload the classes.
console – this command is useful when we want to do some testing on the code we write, including the HTML views. For example
[product-catalog] $ console [info] Starting scala interpreter… [info] Welcome to Scala version 2.11.1 (OpenJDK 64-Bit Server VM, Java 1.7.0_60). Type in expressions to have them evaluated. Type :help for more information.
in Play framework the view template is actually a function, if we open the file app/views/index.scala.html we will see the first line is the method signature, “@(message: String)“, which means that this template is taking 1 String type parameter. I will discuss more about view later.
scala> views.html.index(“I am running this from console.”) res2: play.twirl.api.HtmlFormat.Appendable = <!DOCTYPE html>
we can import class from classpath and run it in the console.
scala> import org.apache.commons.lang3.StringUtils import org.apache.commons.lang3.StringUtils
scala> StringUtils.join((“A”,“B”,” and “,“C”)) res2: String = (A,B, and ,C)
reload – to reload the configuration we changed.
update – if we added or changed the libraries imported in the configuration file, we will need to run this command in order to retrieve the new libraries.
compile – compiling your code
test – run the test case
clean – cleaning up all the files generated from the build
tasks – to list out all the commands defined for current project.