[groovy-user] Struggling with grape/grab

126 views
Skip to first unread message

KARR, DAVID

unread,
Apr 17, 2014, 2:13:17 PM4/17/14
to us...@groovy.codehaus.org
I'm trying to write a short groovy script to do a sql query. I got it working by explicitly setting the classpath to point to the Oracle driver jar, but I'd prefer to have this work with Grape.

I have the Oracle driver jar on a Nexus repo on our intranet.

This is my prototype script:
-----------------
#! env groovy
//@GrabResolver(name='OurRepo', root='http://...')
//@Grab(group='oracle.jdbc', module='oracle.jdbc.OracleDriver', version='1.0.0')
import groovy.sql.Sql
sql = Sql.newInstance('jdbc:oracle:thin:@host:1521:cclabprd',
'cclabro', 'password', 'oracle.jdbc.driver.OracleDriver')
sql.eachRow("select gd.GRPDSCRPTN_TITLE from GRPDSCRPTN gd join GROUPUSERS gu on gu.GROUPUSERS_GROUPID = gd.GRPDSCRPTN_ID join USER_VIEW u on u.ID = gu.GROUPUSERS_USERID where u.login = 'us2300'") { println "$it" }
---------------------

This runs quickly when I run it with a "-cp" command-line parameter pointing to my local install of the "ojdbc6.jar".

When I instead comment back in the @GrabResolver and @Grab lines, and then add "-Dgroovy.grape.report.downloads=true" to the command line, it prints the following and then hangs:
------------------
Resolving dependency: oracle.jdbc#oracle.jdbc.OracleDriver;1.0.0 {default=[default]}
------------------

I first ran this with Groovy 2.2.2. I also tried it with 2.3.0-beta2, but that fails with an even more useless error:
----------------------
Caught: java.net.MalformedURLException: unknown protocol: c
java.net.MalformedURLException: unknown protocol: c
-----------------------

When I added "-d" to the command line, I get this:
----------------------
at java.net.URL.<init>(URL.java:592)
at java.net.URL.<init>(URL.java:482)
at java.net.URL.<init>(URL.java:431)
at java.net.URI.toURL(URI.java:1096)
at groovy.lang.GroovyCodeSource.<init>(GroovyCodeSource.java:162)
at groovy.ui.GroovyMain.getScriptSource(GroovyMain.java:448)
at groovy.ui.GroovyMain.processOnce(GroovyMain.java:627)
at groovy.ui.GroovyMain.run(GroovyMain.java:379)
at groovy.ui.GroovyMain.process(GroovyMain.java:365)
at groovy.ui.GroovyMain.processArgs(GroovyMain.java:124)
at groovy.ui.GroovyMain.main(GroovyMain.java:104)
....
--------------

I'm running this in Cygwin, so perhaps something is getting confused about navigating the PATH.

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

http://xircles.codehaus.org/manage_email


Schalk Cronj é

unread,
Apr 17, 2014, 2:17:04 PM4/17/14
to us...@groovy.codehaus.org
You need @GrabConfig(systemClassLoader=true) as well for JDBC drivers.

(http://groovy.codehaus.org/Grape)
-- 
Schalk W. Cronjé
@ysb33r

KARR, DAVID

unread,
Apr 17, 2014, 2:23:07 PM4/17/14
to us...@groovy.codehaus.org

And what is that supposed to do?

 

It makes no difference in my script.

Jamie Echlin

unread,
Apr 17, 2014, 5:12:13 PM4/17/14
to us...@groovy.codehaus.org
I've only been able to get this to work when creating the connection myself... imho there is some classloading issues with groovy.sql.Sql that I have not had time to debug and create a proper report about.

This method works ok for me: https://jamieechlin.atlassian.net/wiki/display/GRV/Connecting+to+Databases - although might be specific to my environment.

Bob Brown

unread,
Apr 17, 2014, 9:30:33 PM4/17/14
to us...@groovy.codehaus.org
Is this helpful to you?

http://wordpress.transentia.com.au/wordpress/2014/02/22/grabbing-a-library-that-is-not-in-maven/

BOB

> -----Original Message-----
> From: Jamie Echlin [mailto:jamie....@gmail.com]
> Sent: Friday, 18 April 2014 7:12 AM
> To: us...@groovy.codehaus.org
> Subject: Re: [groovy-user] Struggling with grape/grab
>
Reply all
Reply to author
Forward
0 new messages