Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do you use play framework as a library, in a scala project

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.

like image 557
matanster Avatar asked Mar 17 '16 12:03

matanster


1 Answers

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.

like image 187
matanster Avatar answered Sep 26 '22 03:09

matanster