Using play2-war plugin with Play 2.2.2
March 13, 2014|Posted in: Web Application Programming
I recently worked on a project which used the Django framework, I learned a few things along the way:
- Development frameworks make things a lot faster and easier.
- I don’t really care for Python
When my next project came along I started looking at Java frameworks, and I stumbled across the Play Framework. It did everything I wanted it to do and then some. It used established technologies with good abstractions so I didn’t have to try to learn all of them. I started through several of the samples and then launched into a small application of my own just to see how things worked. I was pleased to find that I had a working application within a very short time.
Next up, deploying it to my Tomcat 7 server, and that is when reality hit me right in the face. For reasons of their own, the Play team has decided that deploying to Tomcat, JBoss and other containers is no longer on their radar. They provide a native container and have partnered with Typesafe to deploy to several cloud infrastructures. This is all great, except my management is never going to allow me to run in that environment. After sifting through the Play documentation, reading several stack overflow articles and two days of frustration I found the play2-war plugin, there were even instructions for building a War file without the plugin. Problem Solved!
Unfortunately, neither the instructions for building without the plugin or the play2-war Configuration instructions worked for Play 2.2.2 After a little trial and error I did hit upon the configuration which works:
- Place the following line in [yourApplicationName]/project/plugins.sbt
addSbtPlugin("com.github.play2war" % "play2-war-plugin" % "1.2-beta4")
- Place the following lines in [yourApplicationName]/project/build.svt
Play2WarKeys.servletVersion := "3.0"
- open a command prompt
- cd into [yourApplicationName]
- Type: play war
- If everything is configured properly you should see:
[info] Build WAR package for servlet container: 3.0
[info] Packaging /home/yourApplicationName/yourApplicationName-1.0-SNAPSHOT.war
A few notes on the configuration above, the war file will create the war with the version number from the build.sbt appended on the end, depending on how you deploy your application this could end up appended to the name of your path. You must also select the correct Play2WarKeys.servletVersion setting for your container. They can be found on the Play2War configuration page
I hope this helps someone not have to struggle through this on their own
General purpose computer geek.