## 12.3 Understanding a Plug-ins Structure

As as mentioned previously, a plugin is merely a regular Grails application with a contained plug-in descriptors. 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

Essentially when a plugin is installed into a project, 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 can go in the `web-app` directory. You can then link to static resources just like in an application (example below 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 & 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.