Javaplugin - opensas/Play20Es GitHub Wiki

Writing Plugins

Esta página todavía no ha sido traducida al castellano. Puedes ayudarnos con la tarea simplemente presionando el botón Edit Page. Para más información puedes leer esta guía para el traductor. Aquí puedes ver cuánto nos falta para terminar la traducción.

Play 2.0 comes with a few plugins predefined for all applications, these plugins are the following:

  • DBPlugin -> providing a JDBC datasource
  • EvolutionPlugin -> provides migration (only available if db was configured)
  • EbeanPlugin -> provides Ebean support_ (only available if db was configured)_
  • MessagesPlugin - > provides i18n support
  • BasicCachePlugin -> provides in-memory caching
  • GlobalPlugin -> 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, just like this 5000:com.example.MyPlugin

the number represents the plugin loading order, by setting it to > 1000 we can make sure it's loaded after the global plugins

⚠️ **GitHub.com Fallback** ⚠️