Adding JARs to Grails classpath

View: New views
5 Messages — Rating Filter:   Alert me  

Adding JARs to Grails classpath

by Björn Wilmsmann :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hi,

how do I add JAR files that do not reside in ${basedir}/lib to the  
classpath so they are recognised at compile time? I've tried
eventSetClasspath = { rootLoader ->
        rootLoader.addURL(...)
}
in ${basedir}/scripts/Events.groovy : The URLs are added to the root  
loader but the packages in the JARs are not recognised by the compiler.

--
Best regards,
Bjoern Wilmsmann





PGP.sig (193 bytes) Download Attachment

Re: Adding JARs to Grails classpath

by Gregory W. Bond :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

i've just bumped into this same issue (and unfortunately no one responded to björn's query back in july) - i scanned JIRA and no relevant bugs jumped out at me - so what are we both doing wrong here?

i went as far as to print out the the rootLoader URLs after i added my jar path to ensure that the external jar was added - i went even further and invoked rootLoader.loadClass() on the one of the external jar classes to make sure the rootLoader could get at everything it needed to (and it could) - however when it came to compile time the compiler acted as though the jar wasn't in its classpath - so where's the disconnect between the rootLoader classpath and the grails compiler classpath?

greg


Björn Wilmsmann wrote:
Hi,

how do I add JAR files that do not reside in ${basedir}/lib to the  
classpath so they are recognised at compile time? I've tried
eventSetClasspath = { rootLoader ->
        rootLoader.addURL(...)
}
in ${basedir}/scripts/Events.groovy : The URLs are added to the root  
loader but the packages in the JARs are not recognised by the compiler.

--
Best regards,
Bjoern Wilmsmann




 

Re: Adding JARs to Grails classpath

by Gregory W. Bond :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

after poking around in the source code this afternoon i discovered an answer to this - my overall impression is that that the documentation for the SetClasspath event is misleading and needs clarification - furthermore, the undocumented solution that i discovered needs documenting

first of all, i still don't understand what is to be gained by updating the rootLoader classpath in response to a SetClasspath event - what i have established is that it has *nothing* to do with the grails compile classpath (used by groovyc/javac) - the grails documentation should make this explicit and, furthermore, explain what can be achieved with this mechanism

as for the undocumented solution to the problem: specify the external jars/classes in the file grails-app/conf/PreInit.groovy - the file should define the property grails.compiler.dependencies - this property specifies the external/jars classes in a form that can be parsed by an Ant FileScanner (http://commons.apache.org/jelly/tag-reference/ant_fileScanner.html) - these files will be added to the groovyc/javac invocations performed during grails compilation operations

e.g. grails.compiler.dependencies = { fileset(file:'/Users/greg/sailfin-build51/lib/ssa-api.jar') }

greg


i've just bumped into this same issue (and unfortunately no one responded to björn's query back in july) - i scanned JIRA and no relevant bugs jumped out at me - so what are we both doing wrong here?

i went as far as to print out the the rootLoader URLs after i added my jar path to ensure that the external jar was added - i went even further and invoked rootLoader.loadClass() on the one of the external jar classes to make sure the rootLoader could get at everything it needed to (and it could) - however when it came to compile time the compiler acted as though the jar wasn't in its classpath - so where's the disconnect between the rootLoader classpath and the grails compiler classpath?

greg


Björn Wilmsmann wrote:
Hi,

how do I add JAR files that do not reside in ${basedir}/lib to the  
classpath so they are recognised at compile time? I've tried
eventSetClasspath = { rootLoader ->
        rootLoader.addURL(...)
}
in ${basedir}/scripts/Events.groovy : The URLs are added to the root  
loader but the packages in the JARs are not recognised by the compiler.

--
Best regards,
Bjoern Wilmsmann




 


Re: Adding JARs to Grails classpath

by Gregory W. Bond :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

http://jira.codehaus.org/browse/GRAILS-3439

On Sun, Sep 28, 2008 at 10:02 PM, Gregory W. Bond
<bond.gregory@...> wrote:

>
> after poking around in the source code this afternoon i discovered an answer
> to this - my overall impression is that that the documentation for the
> SetClasspath event is misleading and needs clarification - furthermore, the
> undocumented solution that i discovered needs documenting
>
> first of all, i still don't understand what is to be gained by updating the
> rootLoader classpath in response to a SetClasspath event - what i have
> established is that it has *nothing* to do with the grails compile classpath
> (used by groovyc/javac) - the grails documentation should make this explicit
> and, furthermore, explain what can be achieved with this mechanism
>
> as for the undocumented solution to the problem: specify the external
> jars/classes in the file grails-app/conf/PreInit.groovy - the file should
> define the property grails.compiler.dependencies - this property specifies
> the external/jars classes in a form that can be parsed by an Ant FileScanner
> (http://commons.apache.org/jelly/tag-reference/ant_fileScanner.html) - these
> files will be added to the groovyc/javac invocations performed during grails
> compilation operations
>
> e.g. grails.compiler.dependencies = {
> fileset(file:'/Users/greg/sailfin-build51/lib/ssa-api.jar') }
>
> greg
>
>
> Gregory W. Bond wrote:
>>
>> i've just bumped into this same issue (and unfortunately no one responded
>> to björn's query back in july) - i scanned JIRA and no relevant bugs
>> jumped out at me - so what are we both doing wrong here?
>>
>> i went as far as to print out the the rootLoader URLs after i added my jar
>> path to ensure that the external jar was added - i went even further and
>> invoked rootLoader.loadClass() on the one of the external jar classes to
>> make sure the rootLoader could get at everything it needed to (and it
>> could) - however when it came to compile time the compiler acted as though
>> the jar wasn't in its classpath - so where's the disconnect between the
>> rootLoader classpath and the grails compiler classpath?
>>
>> greg
>>
>>
>>
>> Björn Wilmsmann wrote:
>>>
>>> Hi,
>>>
>>> how do I add JAR files that do not reside in ${basedir}/lib to the
>>> classpath so they are recognised at compile time? I've tried
>>> eventSetClasspath = { rootLoader ->
>>>      rootLoader.addURL(...)
>>> }
>>> in ${basedir}/scripts/Events.groovy : The URLs are added to the root
>>> loader but the packages in the JARs are not recognised by the compiler.
>>>
>>> --
>>> Best regards,
>>> Bjoern Wilmsmann
>>>
>>>
>>>
>>>
>>>
>>>
>>
>>
>
> --
> View this message in context: http://www.nabble.com/Adding-JARs-to-Grails-classpath-tp18344745p19717488.html
> Sent from the grails - user mailing list archive at Nabble.com.
>
>
> ---------------------------------------------------------------------
> To unsubscribe from this list, please visit:
>
>    http://xircles.codehaus.org/manage_email
>
>
>

---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email



Re: Adding JARs to Grails classpath

by Peter Ledbrook-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hi,

> after poking around in the source code this afternoon i discovered an answer
> to this - my overall impression is that that the documentation for the
> SetClasspath event is misleading and needs clarification - furthermore, the
> undocumented solution that i discovered needs documenting

Interesting - I didn't know there was documentation for it. Is this
online or in the code?

> first of all, i still don't understand what is to be gained by updating the
> rootLoader classpath in response to a SetClasspath event - what i have
> established is that it has *nothing* to do with the grails compile classpath
> (used by groovyc/javac) - the grails documentation should make this explicit
> and, furthermore, explain what can be achieved with this mechanism

I suspect we might revisit this. At the moment the libraries are
already added to the classpath via the "groovy-starter.conf" file, but
I'm not sure this is the appropriate mechanism to use now.

The solution you found with PreInit is in fact the correct one for
extending the classpath, and yes it is undocumented at the moment.
Thanks for raising the issue. I have set it to be fixed for 1.0.4.

Cheers,

Peter

--
Software Engineer
G2One, Inc.
http://www.g2one.com/

---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email


LightInTheBox - Buy quality products at wholesale price