17.3 Understanding a Plugin's Structure 2.4.4

See the light - agile, industrial strength, rapid web application development made easy

(Quick Reference) # 17.3 Understanding a Plugin's Structure - Reference Documentation Authors: Graeme Rocher, Peter Ledbrook, Marc Palmer, Jeff Brown, Luke Daley, Burt Beckwith, Lari Hotari Version: 2.4.4 ## 17.3 Understanding a Plugin's Structure As as mentioned previously, a plugin is basically a regular Grails application with a plugin descriptor. However when installed, the structure of a plugin differs slightly. For example, take a look at this plugin directory structure:
    + grails-app
         + controllers
         + domain
         + taglib
         etc.
     + lib
     + src
         + java
         + groovy
     + web-app
         + js
         + css
When a plugin is installed the contents of the `grails-app` directory will go into a directory such as `plugins/example-1.0/grails-app`. They will not be copied into the main source tree. A plugin never interferes with a project's primary source tree. Dealing with static resources is slightly different. When developing a plugin, just like an application, all static resources go in the `web-app` directory. You can then link to static resources just like in an application. This example links to a JavaScript source:
    <g:resource dir="js" file="mycode.js" />
When you run the plugin in development mode the link to the resource will resolve to something like `/js/mycode.js`. However, when the plugin is installed into an application the path will automatically change to something like `/plugin/example-0.1/js/mycode.js` and Grails will deal with making sure the resources are in the right place. There is a special `pluginContextPath` variable that can be used whilst both developing the plugin and when in the plugin is installed into the application to find out what the correct path to the plugin is. At runtime the `pluginContextPath` variable will either evaluate to an empty string or `/plugins/example` depending on whether the plugin is running standalone or has been installed in an application Java and Groovy code that the plugin provides within the lib and `src/java` and `src/groovy` directories will be compiled into the main project's `web-app/WEB-INF/classes` directory so that they are made available at runtime. | Quick Reference (hide)