Play Framework Start/Stop Bash Scripts

   play stage

start.sh:

    #!/bin/bash
    nohup /var/play/myapp/target/universal/stage/bin/myapp-Dhttp.port=8484 &

stop.sh:

    #!/bin/bash
    pid=`cat /var/play/myapp/target/universal/stage/RUNNING_PID 2> /dev/null`
    if [ "$pid" == "" ]; then echo "play app is not running"; exit 0; fi
    echo "Stopping play app..."
    kill -SIGTERM $pid

tail.sh

   #!/bin/bash
   tail -f /var/play/myapp/target/universal/stage/logs/application.log
Advertisements

Play Framework 2.0 Java Controller Route Sub-Packages/Folders

The Play Framework is an awesome change from JavaEE. I like how they embrace Object Oriented design throughout the framework. The Play Framework is Java’s version of Django or Ruby on Rails. By default, it uses EBean as the ORM and it has been a refreshing change from Hibernate as well. It is the the most rapid web development framework that I have used in Java. I came across my first curve-ball with it that was not easy to find when googling it.

I don’t like flat project structures. I always plan that even the smallest projects will have a ton of models, controllers, and views and they should all be segregated in their own folders/packages. I placed my logged-in controllers in their own package in controllers.tracker.*. The trick was to get the routes object to work.

I assumed that routes.tracker.DashboardController.index() would work, nope. Apparently there is a routes object at each level of the package structure under the controllers package. So here’s what worked:

    return redirect(controllers.tracker.routes.DashboardController.index());