You are viewing the documentation for the 2.2.5 release in the 2.2.x series of releases. The latest stable release series is 3.0.x.
§Writing Plugins
Play comes with a few plugins predefined for all applications, these plugins are the following:
DBPlugin
-> providing a JDBC datasourceEvolutionPlugin
-> provides migration (only available if db was configured)EbeanPlugin
-> provides Ebean support (only available if db was configured)MessagesPlugin
- > provides i18n supportBasicCachePlugin
-> provides in-memory cachingGlobalPlugin
-> executes application’s settings
However, one can easily add a new plugin to an application by following these steps:
- Implement
play.Plugin
(see this for an example). - This plugin should be available in the application either through pulling in it from a maven repository and referencing it
as an app dependency or the plugin code can be part of a play application. - You can access it like:
import static play.api.Play.*;
import static play.libs.Scala.*;
public Myplugin plugin() {
return orNull(unsafeApplication().plugin(MyPlugin.class)).api();
}
which will return an instance or subclass of MyPlugin
fully initialized or null
.
- In your app create a file:
conf/play.plugins
and add a reference to your plugin:
5000:com.example.MyPlugin
The number represents the plugin loading order. By setting it to > 10000 we can make sure it’s loaded after the global plugins.