Overview | Package | Class | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: REQUIRED | OPTIONAL | DETAIL: ELEMENT

## groovy.lang
Annotation Type GrabConfig

    @Retention(value=SOURCE)
    @Target(value={CONSTRUCTOR,FIELD,LOCAL_VARIABLE,METHOD,PARAMETER,TYPE})
    public @interface GrabConfig

Use within a `@Grapes` annotation to modify grab configuration.

An example involving databases:

     @Grapes([
         @Grab('mysql:mysql-connector-java:5.1.6'),
         @GrabConfig(systemClassLoader=true)
     ])
     import groovy.sql.Sql

     def sql=Sql.newInstance("jdbc:mysql://localhost/test", "user", "password", "com.mysql.jdbc.Driver")
     println sql.firstRow('SELECT * FROM INFORMATION_SCHEMA.COLUMNS')

Another example involving XStream:

     @Grapes([
         @Grab('com.thoughtworks.xstream:xstream:1.3.1'),
         @Grab('xpp3:xpp3_min:1.1.4c'),
         @GrabConfig(systemClassLoader=true, initContextClassLoader=true)
     ])
     import com.thoughtworks.xstream.*

     class Staff {
         String firstname, lastname, position
     }

     def xstream = new XStream()
     def john1 = new Staff(firstname:'John',
                          lastname:'Connor',
                          position:'Resistance Leader')

     // write out to XML file
     new File("john.xml").withOutputStream { out ->
         xstream.toXML(john1, out)
     }

     // now read back in
     def john2
     new File("john.xml").withInputStream { ins ->
         john2 = xstream.fromXML(ins)
     }

     println john2.dump()

Optional Element Summary
Modifier and Type | Optional Element and Description
--- | ---
`boolean` | `initContextClassLoader` Set to true if you want the context classloader to be initialised to the classloader of the current class or script.
`boolean` | `systemClassLoader` Set to true if you want to use the system classloader when loading the grape.

### systemClassLoader

    public abstract boolean systemClassLoader

  Set to true if you want to use the system classloader when loading the grape. This is normally only required when a core Java class needs to reference the grabbed classes, e.g. for a database driver accessed using DriverManager.

  Default:
    false

### initContextClassLoader

    public abstract boolean initContextClassLoader

  Set to true if you want the context classloader to be initialised to the classloader of the current class or script. This is useful for libraries or frameworks that assume that the context classloader has been set. But be careful when using this flag as your script or class might behave differently when called directly (from the command line or from an IDE) versus when called from within a container, e.g. a web container or a JEE container.

  Default:
    false

Overview | Package | Class | Tree | Deprecated | Index | Help
| Copyright © 2003-2010 The Codehaus. All rights reserved.
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: REQUIRED | OPTIONAL | DETAIL: ELEMENT