Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Deploy play as a war file into a servlet container, even if it uses JPA heavily?

I am fairly new to play, in fact i read right at the moment about it, and what should I say...Questions over questions. At the moment I am kickstarting a project which relies on a lot of special java libraries (hibernate-spatial, jts, etc...). Because it also should implement a comprehensive REST API, I had to decide between Django versus classic JavaEE Glassfish app.

But now I think with play I get the best of both worlds and I really would like to dive deeper into this.

One feature of play, I really can't imagine, is to deploy play apps as WAR files even to a simple Servlet Container like tomcat.

So is it right, that if my play app uses a JPA persistance layer based on hibernate/hibernate-spatial still can be deployed as WAR file to a simple tomcat servlet container? Or do I need a JavaEE Application Server at least?

I can't believe it...

like image 466
Jürgen Zornig Avatar asked Feb 20 '13 17:02

Jürgen Zornig


2 Answers

Play 2 applications can be deployed as a war using the Play 2 War plugin. I have no experience with it myself, but it seems a working solution for now. From what I've read from the forums WAR packaging should still be on the cards for a future release.

There's nothing special about deploying a Play 2 app as a war. A Play 2 app is 'just' a Java program that responds to HTTP requests*, like any Java Servlet applications do. It can be run as-is* in a servlet container if some plugin makes sure that the HTTP requests the servlet container responds to are forwarded properly to the Play 2 app.

In general, Play 2 allows you to use almost all Java technology that is available. However, because a Play 2 app doesn't run in a servlet natively, it prohibits you from using a set of Java EE libraries that assume you use a Java servlet to respond to requests. This is no problem for Hibernate or other ORM/database libraries, but it's a problem if your libraries require access to the HTTP communication (e.g. Spring Web Security).

If Django is an option for your project, I doubt your Java requirements include such a specific library. You should also review whether an actual servlet container is a necessity for your application at all - Play apps run just fine without one.

* I know this is a perverse oversimplification

like image 126
DCKing Avatar answered Sep 28 '22 16:09

DCKing


You don't need a full Java EE server, or even a standalone servlet container like Tomcat. Play basically IS its own server! To be more precise, Play comes bundles with JBoss Netty... an embeddable Java server that uses some of the same concepts as Node.js. If you've used Django before, then the concept is a lot like:

python manage.py runserver

Many Play developers use a PaaS (i.e. "cloud") service, such as Heroku or AppFog. If you are deploying to your own traditional dedicated server, then you install the Play framework on that machine just as you would Tomcat. The documentation for deployment goes into more detail here.

The first version of Play also had an option for packaging your application as a WAR file, for deployment to a traditional servlet container. Play 2.0 dropped this support. It was on the roadmap to come back in Play 2.1, but apparently did not make it.

I would like to see WAR file functionality restored, because most enterprise shops are heavily invested in their deployment infrastructure, and are hostile to rapid change. It's worth mentioning that due to the API'S used, a Play 2.1 app would never run on a version of Tomcat older than 7 no matter what.

However, Play 2.1 does have the ability to bundle up applications into deployable ZIP files, similar to WAR files. These standalone ZIP's still require that you install Play on the server, but they make it easier to package up and deploy your apps from one machine to another.

like image 35
Steve Perkins Avatar answered Sep 28 '22 15:09

Steve Perkins