If so, please check this post out, since its author has just spent about 3h trying to integrate the latest (so far) 2.1 version of Play framework with Cloud Foundry PaaS, and in the end all efforts have been paid off to him.
Well, everything had started when I wanted to move from Anorm to Slick for DB management and that's why I needed Scala 2.10.0 and thus Play 2.1.
I already knew for integration problems of Play 2.1 and Cloud Foundry, but on the other hand CF is one of the promising PaaS platforms which offers great resources in its beta phase (2GB RAM, arbitrary number of applications instances, PostgreSQL 9.0, RabitMQ, and few other services - all for free), so I just didn't want to miss a thing.
On the many places I could read how "Cloud Foundry doesn't support Play 2.1", how "it breaks its integration", etc., etc., and guess what - I've just managed to solve this issue and now my application is running on Play 2.1 right there: http://pijaca.cloudfoundry.com/ (okay, I'm still developing it, so please, leave critics behind for app itself ;)).
Since I guessed that there could be also people who want to try Play 2.1 with Cloud Foundry for various reasons, I just wanted to explain how I solved my integration issues, in the following steps.
Play 2.1 with Cloud Foundry - Integration Steps
1. Create Play 2.1 application or migrate your existing Play 2.0.x applications to Play 2.1. If you are doing migration, take special care to project/Build.scala, project/plugins.sbt and project/build.properties files.
In my case, they look like this:
Build.scala
import sbt._
import Keys._
import play.Project._
object ApplicationBuild extends Build {
val appName = "pijaca"
val appVersion = "1.0-SNAPSHOT"
val appDependencies = Seq(
// Add your project dependencies here,
jdbc,
anorm,
"postgresql" % "postgresql" % "8.4-702.jdbc4",
"org.hibernate" % "hibernate-entitymanager" % "3.6.9.Final"
)
val main = play.Project(appName, appVersion, appDependencies).settings(
// Add your own project settings here
)
}
plugins.sbt
// Comment to get more information during initialization
logLevel := Level.Warn
// The Typesafe repository
resolvers += "Typesafe repository" at "http://repo.typesafe.com/typesafe/releases/"
// Use the Play sbt plugin for Play projects
addSbtPlugin("play" % "sbt-plugin" % "2.1.0")
build.properties
sbt.version=0.12.2
2. Download the next libraries:
auto-reconfiguration-0.6.5.jar
play-java-jpa_2.10-2.1.0.jar
hibernate-jpa-2.0-api-1.0.1.Final.jar
from the next locations (respectively):
http://rapidshare.com/files/2061661742/auto-reconfiguration-0.6.5.jar
(original link to vcap-staging project containing built library became inactive in mid-time so I have uploaded it onto Rapidshare)
http://www.versioneye.com/package/play--play-java-jpa_2~10/version/2~1~0
http://www.versioneye.com/package/org~hibernate~javax~persistence--hibernate-jpa-2~0-api/version/1~0~1~Final
Just to mention that here also figures play-java-jdbc_2.10_2.1.0.jar as an additional dependency, but for me it worked even without this library, probably because on my classpath I already had play-java_xxx.jar and play-jdbc_xxx.jar. Since I didn't have problem with this one I haven't checked this in more details.
3. Add the mentioned three libraries onto your classpath.
4. In your conf folder create cloud.conf and cloudfoundry.properties files. They should look like:
cloud.conf
include "application.conf"
include "cloudfoundry.properties"
db.default.driver=${?cloud.services.postgresql.connection.driver}
db.default.url=${?cloud.services.postgresql.connection.url}
db.default.password=${?cloud.services.postgresql.connection.password}
db.default.user=${?cloud.services.postgresql.connection.username}
cloudfoundry.properties
autoconfig=false
Of course, application.conf is your old configuration file. cloud.conf file from this example overrides settings only for PostgreSQL database. In my case, I have only one instance of this service, so that's why "postgresql" figures in those settings. Otherwise, instead of it you should place the name of your service, e.g. "postgresql_service_1".
5. Clean your project. (Because of moving from different versions of Play and Scala I performed first "play clean-all").
play clean compile
play -Dconfig.file=path-to-conf\cloud.conf dist
and since I already saved my deploying information in manifest.yml file, I have just executed:
vmc push
to deploy my application to the Cloud Foundry.
For the curious ones, my manifest.yml file looks something like this:
---
applications:
- name: pijaca
framework: play
runtime: java7
memory: 1G
instances: 1
url: pijaca.${target-base}
path: dist/pijaca-1.0-SNAPSHOT.zip
services:
PostgreSQL_1:
vendor: postgresql
version: '9.0'
tier: free
After couple of minutes my application is uploaded and now it's running happily on CF! :)
So far, that should be all you need to deploy your Play 2.1 application onto the Cloud Foundry. If I found something else that I missed here, I'll update this post later on.
Hopefully, someone will find this post helpful in the end.
Cheers,
https://github.com/cloudfoundry/vcap-staging/blob/master/lib/vcap/staging/plugin/resources/auto-reconfiguration-0.6.5.jar - Is there any other place I can download that library. The link returns a not so nice 404.
ReplyDeleteHi Nicolae,
DeleteThank you for remark on inactive link. It's been removed in the mid-time - together with the whole blob folder from the root of their project which contained this library.
If you want to do it by yourself, you can still clone the project containing auto-reconfiguration from here: https://github.com/cloudfoundry/vcap-java and try to build the library.
However, if you have any problems with building library or just want to skip that step, I have uploaded "auto-reconfiguration-0.6.5.jar" onto Rapidshare so you can download it from there: http://rapidshare.com/files/2061661742/auto-reconfiguration-0.6.5.jar
The post has been also updated accordingly.
Thanks,
Aleksandar
Thank you so much for taking the time to help me.
DeleteNo problem,
DeleteI'm glad if I could help you to solve your issues.
Cheers,
Hi,
ReplyDeleteI am getting exception in auto configuration in play 2.3. Can you look at this..https://github.com/cloudfoundry/java-buildpack/issues/322
Thanks in advanced
Thank you for sharing the blog.
ReplyDeletePivotal Cloud Foundry Online Training
this one is very nice blog.
ReplyDeleteFull Stack Training in Chennai | Certification | Online Training Course | Full Stack Training in Bangalore | Certification | Online Training Course | Full Stack Training in Hyderabad | Certification | Online Training Course | Full Stack Training in Pune | Certification | Online Training Course | Full Stack Training | Certification | Full Stack Online Training Course