Tuesday, June 24, 2014

Play 2 framework WAR file

Play 2 framework is a nice framework for writing web applications in Java/Scala. Play runs it's own netty server so you get it up and running by just writing play run. It detects file changes and recompiles classes as needed upon page refresh in development mode.

A small catch is that Play does not natively support running in a container, e.g. Jetty, Tomcat, Glassfish, or JBoss. In fact it doesn't support ServletContext at all as far as I can see. (See http://www.playframework.com/documentation/1.2.2/faq and http://guillaumebort.tumblr.com/post/558830013/why-there-is-no-servlets-in-play)
This is a minus when trying to get started with Play in existing server environments. Luckily Damien Lecan started an open source project to build WAR files from Play, play2war plugin.

Follow https://github.com/play2war/play2-war-plugin/wiki/Configuration to install the plugin.

Basically your Build.scala file should look something like:
import com.github.play2war.plugin._
object ApplicationBuild extends Build {
    val main = play.Project(appName, appVersion, appDependencies)
        .settings(Play2WarPlugin.play2WarSettings: _*)
        .settings(
      // Add your own project settings here 
      Play2WarKeys.servletVersion := "3.0"
    )

}

and your plugins.sbt:
// Use play2war for creating war files using 'play war'
addSbtPlugin("com.github.play2war" % "play2-war-plugin" % "1.2-beta4")

And hopfully, magic! (Note currently (2014.06.24) only support Play 2.2.1)

Once installed, just run play war and a war file is created for you. In addition you will need a config file for your application, the application.conf in your project folder, and any extra files/folders like the private folder of your project.

No comments:

Post a Comment