source: Dev/branches/play-2.0.1/documentation/manual/sandbox/Javaplugin.md @ 322

Last change on this file since 322 was 322, checked in by hendrikvanantwerpen, 13 years ago

Added Play! framework and application with Jena dependency. Working on
the basic things now (login/register), after that start implementing
our data model.

File size: 1.5 KB
Line 
1# Writing Plugins
2
3Play 2.0 comes with a few plugins predefined for all applications, these plugins are the following:
4
5* ```DBPlugin``` -> providing a JDBC datasource
6* ```EvolutionPlugin``` -> provides migration  _(only available if db was configured)_
7* ```EbeanPlugin``` -> provides Ebean support_ (only available if db was configured)_
8* ```MessagesPlugin``` - > provides i18n support
9* ```BasicCachePlugin``` -> provides in-memory caching
10* ```GlobalPlugin``` -> executes application's settings
11
12However, one can easily add a new plugin to an application by following these steps:
13
14* implement ```play.Plugin``` (see [this](https://github.com/playframework/Play20/blob/master/framework/src/play/src/main/java/play/db/ebean/EbeanPlugin.java) for an example)
15* this plugin should be available in the application either through pulling in it from a maven repository and referencing it
16as an app dependency or the plugin code can be part of a play application
17* you can access it like
18
19```java
20import static play.api.Play.*;
21import static play.libs.Scala.*;
22
23public Myplugin plugin() {
24   return orNull(unsafeApplication().plugin(MyPlugin.class)).api();
25}
26```
27
28which will return an instance or subclass of ```MyPlugin``` fully initialized or ```null```.
29
30* in your app create a file: ```conf/play.plugins``` and add a reference to your plugin, just like this  ```5000:com.example.MyPlugin```
31
32_the number represents the plugin loading order, by setting it to > 1000 we can make sure it's loaded after the global plugins_
Note: See TracBrowser for help on using the repository browser.