7

Use Play Framework as a component got a server up, but configuring the file system paths for routes file, views, etc, give or take having to take care of a thread pool for the embedded play server is a different story. Basing on the aforementioned, I started a template for including play as a library, but it remains unclear how to wire the paths, hopefully in an IDE-import friendly way too, so that Play can be nicely used in an existing non-play project, as a library.

  • How do you configure the file system paths for the routes file and views?
  • What else should be handled for being as robust as running as the framework?
  • Anything special for bundling the project for deploy with Play now included?

Motivation: Adding Play to a project, in the current state of affairs, means wrapping the project definition and structure around Play, and losing full compilation in sbt (because only run completes the compilation when using the play sbt plugin). As future Spray support is vague and Akka http is beta-ish, using Play as a library seems to plug a hole.

Community
  • 1
  • 1
matanster
  • 15,072
  • 19
  • 88
  • 167
  • It is a neat idea. I think it would be interesting to develop the play application as we normally do, just adding a class (your Server) that allows to run the Play app from within any project. Release the Play app as an Uber jar and import it in any project. Of course, there might be a number of problems with this approach, specifically if play is able to work as a non exploded jar. But it would be a nice workflow. – Jonas Anso Mar 21 '16 at 10:51
  • It might even work as I described previously. https://www.playframework.com/documentation/2.5.x/Deploying#Using-the-SBT-assembly-plugin – Jonas Anso Mar 21 '16 at 11:40
  • Frankly I don't see how your suggestion coincides with what I've described, if anything, I think you describe the opposite flow to what I have in mind and almost working. – matanster Mar 21 '16 at 14:06
  • Sorry, it was not my intention disturbing you. I misunderstood your idea. I will watch your project to see if I get it at a later point. – Jonas Anso Mar 21 '16 at 15:45
  • All cool ;) maybe I just didn't get the relation between the two.. – matanster Mar 21 '16 at 16:42
  • All cool. Good luck with the project. – Jonas Anso Mar 21 '16 at 16:51
  • Well it turns out that managing asset compilation/transformation/building is the worst part of this. I would never fathom why the play team decided to destroy the normal process of compilation in sbt in such a manner that makes this necessary. – matanster Apr 09 '16 at 07:09

1 Answers1

3

Somehow this didn't pop up in google, until someone suggested the link on gitter: https://www.playframework.com/documentation/2.5.x/ScalaEmbeddingPlay

Note that an application.conf file containing the required crypto secret can simply sit under src/main/resources in this embedded mode (up until you want to override it for production as per the documentation about it). This is quite enough for a REST server.

However now back to the docs, in case you want more than REST:

This can be used in conjunction with the Twirl template compiler and Play routes compiler

So for Play view templates (which are twirl templates really), refer to the repo I mention in the question body, in which @JonasAnso kindly enabled exactly that.

matanster
  • 15,072
  • 19
  • 88
  • 167
  • Well it turns out asset management (not included above) [is the worst part of this integration](http://stackoverflow.com/questions/36487410/play-framework-sbt-web-integration-without-play-plugin). Not solved yet. – matanster Apr 09 '16 at 07:11