If you have a couple of play! apps that have a common domain model, the easiest way to share that model is to put it into a module.

play new-module my-shared-model

generates an empty module in the current directory. Put your domain model in my-shared-model/apps/models, add some tests and then you have a choice: Either
1. install the module into the play! framework (see official docs here). This can then be referenced in conf/application.conf using

module.my-shared-model=${play.path}/modules/my-shared-model

or 2. Put the module somewhere well-known and logically related to the apps that share it, and give it a relative reference, e.g.

projects
 |- app1
 |- app2
 |- my-shared-model

conf/application.conf of app1 and app2:

module.my-shared-model=../my-shared-model

Note the module is now resolved relative to the application root.

Start up app1 (or app2) and the console should give you this happy message:

06:54:52,148 INFO  ~ Starting /home/steve/projects/app1
06:54:52,158 INFO  ~ Module my-shared-model is available (/home/steve/projects/app1/../my-shared-model)

Done!

3 thoughts on “quick&easy: Sharing a domain model between two Play! apps

Leave a Reply

Your email address will not be published. Required fields are marked *