Last updated by admin 4 years ago
?????????? {excerpt:hidden=true} Working with Plugins {excerpt}
?????????? {excerpt:hidden=true} Understanding a Plugin's structure {excerpt}
{excerpt:hidden=true} So as mentioned previously, a plugin is merely a regular Grails application with this special file; however when installed, the structure of a plugin differs slightly. For example, take a look at this plugin directory structure: {excerpt}
?????????????????????????????????????????Grails?????????????????????????????????????????????????????????????????????????????
+ grails-app
+ controllers
+ domain
+ taglib
etc.
+ lib
+ src
+ java
+ groovy
+ web-app
+ js
+ css{excerpt:hidden=true}
Basically when a plugin is installed into a project, the stuff within the {{grails-app}} directory will go into a directory like {{$PROJECT_HOME/plugins/example-1.0/grails-app}}. They will NOT be copied into the main source tree. A plugin NEVER messes with a project's primary source tree. {excerpt}
????????????????????????????? {{grails-app}} ???????????{{$PROJECT_HOME/plugins/example-1.0/grails-app}} ?????????????????????????????????????????????????????????????????????????{excerpt:hidden=true}
However, static resources such as those inside the {{web-app}} directory will be copied into the project's web-app directory under a special "plugins" directory for example {{web-app/plugins/example-1.0/js}}. It is therefore the responsibility of the plugin to make sure that it references static resources from the correct place. For example if you were referencing a JavaScript source from a GSP this would be: {excerpt}
???? {{web-app}} ?????????????????? web-app????????? "plugins" ??????(? {{web-app/plugins/example-1.0/js}} ? ) ???????????????????????????????????????????????????GSP??JavaScript????????????
<g:createLinkTo dir="/plugins/example/js" file="mycode.js" />
{excerpt:hidden=true} 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. {excerpt}
???????????? {{lib}}? {{src/java}} ? {{src/groovy}} ????????Java?Groovy???????????????? web-app/WEB-INF/classes?????????????????????????
??????????????????? {excerpt:hidden=true} What a Plugin can and can't do {excerpt}
{excerpt:hidden=true}
A plugin can do just about anything, but a good plugin should be as unintrusive as possible. It should use convention over configuration where possible, otherwise provide an artifact in a project's grails-app/conf directory where configuration can be done. {excerpt}
?????????????????????????????????????????????????? ??????convention over configuration?CoC??????????????????????????????grails-app/conf ????????????????????????????{excerpt:hidden=true}
One thing a plugin cannot do though is modify the web-app/WEB-INF/web.xml or web-app/WEB-INF/applicationContext.xml files. A plugin can participate in web.xml generation, but not modify the file or provide a replacement. A plugin can NEVER change the {{applicationContext.xml}} file, but can provide runtime bean definitions as seen shortly. {excerpt}
???????? web-app/WEB-INF/web.xml ??? web-app/WEB-INF/applicationContext.xml ????????????????????????web.xml?????????????????????????????????????????????? {{applicationContext.xml}} ??????????????????????????????????????????????????????