Srle
Srle

Reputation: 10496

Separate application in different parts, reuse and including

Beginner with play here :) Basically i want application which will have 2 parts(2 projects). One part for front-end and one for admin logic. Both of them will have theirs unique controllers and views and so on.

Both parts(projects) will use same models and business logic, so i want on some way to include these models and business logic to the 2 project mentioned above.

So to recap: A = front-end (controllers, model, views) B = admin(controllers, model, views) C = only model (same for A and B, this part will NOT have any controllers nor views nor routes, etc).

How to do that? How to include C in A and B (through build.sbt?) How to generate play project without controllers, views and so on (i dont want to manually delete stuff).

Upvotes: 2

Views: 199

Answers (2)

josephpconley
josephpconley

Reputation: 1723

There's a good write-up on how to handle multi-projects at http://www.playframework.com/documentation/2.1.x/SBTSubProjects. Specifically, follow the example under "Splitting your web application into several parts" to get a sense of how to split your concerns into modules.

Per your example, I would make A, B, and C all modules of one master Play project, and setup the appropriate dependencies to ensure that module A and B each depend on the dependencies of module C.

Keep in mind that the modules must live in a subdirectory of the master Play project. In the example in that link, all modules would live in a subdirectory called "modules". If you don't like that folder structure constraint, the only recommendation I'd have would be to do a symbolic link to a subfolder.

Upvotes: 2

Didac Montero
Didac Montero

Reputation: 2086

Create a regular Java (my experience in Play is based on Java) project only with the model classes (POJOs).

Copy that project's (C) jar file to /lib folder in Play Framework projects (A and B). You will then be able to use those models anywhere in play (for the view you'll need to declare the full package for the models, and not only the class name). You could also C to the build.stb (if you have maven set up correctly).

Upvotes: 0

Related Questions