Documentation

You are viewing the documentation for Play 1. The documentation for Play 2 is here.

Application modularization

A play application can be assembled from several application modules. This allows you to reuse application components across several application or split a large application into several smaller applications.

What is a module ?

A module is just another play application; however some differences exist in the way resources are loaded for an application module :

You can create a module with the play new command, just like you do for any other application.

How to load external modules from an application

If you want to load external modules from an application, just declare external modules in the application.conf file in the main application.

The default application loads the CRUD module from the standard play modules path.

# Additional modules
# ~~~~~
# A module is another play application. Add a line for each module you want
# to add to your application. Module paths are either absolute or relative to
# the application root.
#
module.crud=${play.path}/modules/crud

Let’s say you have a large application with a CMS component, a forum component, a directory component and so on:

module.cms=../cms
module.forum=../forum
module.directory=../directory

If module paths are relative they are resolved from the main application root.

Load default routes from modules

A module can provide a default routes file. You can load it in the main application routes file, using a special route declaration:

# Import the default CRUD routes
GET     /admin	     module:crud

You can even load routes from all available modules:

GET     /	     module:*