[ 
https://issues.apache.org/jira/browse/GROOVY-7666?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15430616#comment-15430616
 ] 

Paul King edited comment on GROOVY-7666 at 8/22/16 8:30 PM:
------------------------------------------------------------

Is this what you are after?
{noformat}
$ groovy -e "
> def rootLoader = getClass().classLoader.rootLoader
> groovy.grape.Grape.grab(group:'com.h2database', module:'h2', 
> version:'1.4.188', classLoader:rootLoader)
> groovy.sql.Sql.withInstance('jdbc:h2:mem:test_mem', 'sa', '', 
> 'org.h2.Driver') { sql ->
>   println sql.firstRow(/SELECT * FROM INFORMATION_SCHEMA.SETTINGS where NAME 
> = 'info.VERSION'/).value
> }
> "
1.4.188 (2015-08-01)
{noformat}


was (Author: paulk):
Is this what you are after?
{noformat}
$ target/install/bin/groovy -e "
> def rootLoader = getClass().classLoader.rootLoader
> groovy.grape.Grape.grab(group:'com.h2database', module:'h2', 
> version:'1.4.188', classLoader:rootLoader)
> groovy.sql.Sql.withInstance('jdbc:h2:mem:test_mem', 'sa', '', 
> 'org.h2.Driver') { sql ->
>   println sql.firstRow(/SELECT * FROM INFORMATION_SCHEMA.SETTINGS where NAME 
> = 'info.VERSION'/).value
> }
> "
1.4.188 (2015-08-01)
{noformat}

> Grapes do not work with groovy -e
> ---------------------------------
>
>                 Key: GROOVY-7666
>                 URL: https://issues.apache.org/jira/browse/GROOVY-7666
>             Project: Groovy
>          Issue Type: Bug
>    Affects Versions: 2.3.0-beta-2
>            Reporter: siegfried heintze
>            Priority: Critical
>
> I cannot use grapes on the command line with the groovy -e feature as 
> documented in my Sept 4 2015 email on the groovy emil list.  Subsequent Email 
> conversations on the groovy mailing list with  [email protected] 
> indicate that 
> (1) The bug is reproducible by Thibault Kruse
> (2) It has been fixed by Thibault Kruse
> (3) we are waiting for someone to review his code so it can be merged with 
> the mainline and released.
> Here is my original email from Sep 4 2015:
> The script below works with groovy 2.3.0-beta-2 with the groovy program. I 
> want to move the SQL code to separate text files and execute it from (1) 
> "groovy -e" (2) groovy-console and (3) groovysh.
> After looking at 
> http://www.techper.net/2010/04/19/groovy-grape-adding-dependencies-to-root-classloader/
>  here is my first attempt using Cygwin on windows 8 and groovy that is not 
> working:
> {code}
> groovy -e "import groovy.sql.Sql
> import groovy.xml.MarkupBuilder;
> import groovy.sql.Sql
>  
> def classLoader = this.getClass().getClassLoader();
> while 
> (!classLoader.getClass().getName().equals('org.codehaus.groovy.tools.RootLoader'))
>  {
>   classLoader = classLoader.getParent()
> }
> groovy.grape.Grape.grab(group:'com.h2database', module:'h2', 
> version:'1.4.188')
> def sql = Sql.newInstance('jdbc:h2:mem:test_mem', 'sa', '', 'org.h2.Driver');"
> {code}
> Caught: java.lang.ClassNotFoundException: org.h2.Driver
> java.lang.ClassNotFoundException: org.h2.Driver
>  at script_from_command_line.run(script_from_command_line:10)
> As you can see, I'm trying to convert the @GrabConfig which does not seem to 
> work with "groovy -e".



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)

Reply via email to