[groovy-user] Gmaven console + Groovy Sql classloading

4 views
Skip to first unread message

Tom Nichols

unread,
Sep 18, 2009, 10:44:23 AM9/18/09
to user
I'm seeing a problem w/ GMaven classloading and groovy.sql.Sql
This is related to this bug: http://jira.codehaus.org/browse/MGROOVY-166

But it's not working for me. Can someone try out the attached POM and
let me know if I'm crazy?

Instructions:
Put the POM in a directory.
Run "mvn groovy:console"
Type the following and execute:

new org.hsqldb.jdbcDriver()
groovy.sql.Sql.loadDriver('org.hsqldb.jdbcDriver')

I get this (on the second line, not the first):

Exception thrown: org.hsqldb.jdbcDriver

java.lang.ClassNotFoundException: org.hsqldb.jdbcDriver
at java.net.URLClassLoader$1.run(URLClassLoader.java:200)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:188)
at java.lang.ClassLoader.loadClass(ClassLoader.java:307)
at java.lang.ClassLoader.loadClass(ClassLoader.java:252)
at org.codehaus.plexus.classworlds.realm.ClassRealm.loadRealmClass(ClassRealm.java:174)
at org.codehaus.plexus.classworlds.strategy.DefaultStrategy.loadClass(DefaultStrategy.java:67)
at org.codehaus.plexus.classworlds.strategy.ForeignStrategy.loadClass(ForeignStrategy.java:39)
at org.codehaus.plexus.classworlds.realm.ClassRealm.loadClass(ClassRealm.java:201)
at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:320)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:169)
at groovy.sql.Sql.loadDriver(Sql.java:270)
at groovy.sql.Sql$loadDriver.call(Unknown Source)
at ConsoleScript1.run(ConsoleScript1:2)


My environment:
Apache Maven 2.2.0 (r788681; 2009-06-26 09:04:01-0400)
Java version: 1.6.0_16
Java home: /usr/lib/jvm/java-6-sun-1.6.0.16/jre
Default locale: en_US, platform encoding: UTF-8
OS name: "linux" version: "2.6.28-15-generic" arch: "amd64" Family: "unix"

You can see in the POM I'm using Groovy 1.6.4 and Gmaven 1.0-rc-5

Any help? Thanks in advance.

pom.xml

Guillaume Laforge

unread,
Sep 18, 2009, 10:55:12 AM9/18/09
to us...@groovy.codehaus.org
At least, if not more, I can confirm I get the same error :-)

Exception thrown: org.hsqldb.jdbcDriver

java.lang.ClassNotFoundException: org.hsqldb.jdbcDriver
at java.net.URLClassLoader$1.run(URLClassLoader.java:200)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:188)

at java.lang.ClassLoader.loadClass(ClassLoader.java:316)
at java.lang.ClassLoader.loadClass(ClassLoader.java:251)


at org.codehaus.plexus.classworlds.realm.ClassRealm.loadRealmClass(ClassRealm.java:174)
at org.codehaus.plexus.classworlds.strategy.DefaultStrategy.loadClass(DefaultStrategy.java:67)
at org.codehaus.plexus.classworlds.strategy.ForeignStrategy.loadClass(ForeignStrategy.java:39)
at org.codehaus.plexus.classworlds.realm.ClassRealm.loadClass(ClassRealm.java:201)

at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:374)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:164)


at groovy.sql.Sql.loadDriver(Sql.java:270)
at groovy.sql.Sql$loadDriver.call(Unknown Source)

at ConsoleScript0.run(ConsoleScript0:2)

> ---------------------------------------------------------------------
> To unsubscribe from this list, please visit:
>
>    http://xircles.codehaus.org/manage_email
>
>

--
Guillaume Laforge
Groovy Project Manager
Head of Groovy Development at SpringSource
http://www.springsource.com/g2one

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

http://xircles.codehaus.org/manage_email


Guillaume Laforge

unread,
Sep 18, 2009, 11:12:34 AM9/18/09
to us...@groovy.codehaus.org
What is the real usage you're doing with the Sql class?


On Fri, Sep 18, 2009 at 16:44, Tom Nichols <tmni...@gmail.com> wrote:

Tom Nichols

unread,
Sep 18, 2009, 11:18:48 AM9/18/09
to us...@groovy.codehaus.org
Well, I'm trying to run ad-hoc queries through the Groovy console
because I'm seeing a nasty timestamp conversion problem in my code. I
think it's coming from the JDBC driver (Oracle actually) so I wanted
to be able to run my queries in Groovy Sql and inspect the results.
I'm actually using Groovy Sql in my application, so being able to take
code directly from my application and run/tweak them "live" in my
console is a super-great way to debug things... If only I can get
around this classloading issue... :)

Thanks.
-Tom

Guillaume Laforge

unread,
Sep 18, 2009, 11:23:09 AM9/18/09
to us...@groovy.codehaus.org
What I wanted to get at is that there are different ways of using the Sql class.
You could use a new Sql(DataSource / Connection), you could use
Sql.newInstance()...
One of the options may be working and would circumvent your class loading issue.

Tom Nichols

unread,
Sep 18, 2009, 11:30:24 AM9/18/09
to us...@groovy.codehaus.org
Oh sorry... Well since I'm working in the console I don't have access
to an existing DataSource or connection, so I was trying to use

Sql.newInstance( url, user, pass, driver )

But that causes the same error. In the bug report, the final comment
uses "Sql.loadDriver" before calling newInstance, but apparently that
doesn't help for me.

On Fri, Sep 18, 2009 at 11:23 AM, Guillaume Laforge

Guillaume Laforge

unread,
Sep 18, 2009, 11:31:11 AM9/18/09
to us...@groovy.codehaus.org
For instance, this will work and won't give you the class loading issue:


import groovy.sql.Sql
import org.hsqldb.jdbcDriver

def jdbcUrl = 'jdbc:hsqldb:mem:foo'

new Sql(new jdbcDriver().getConnection(jdbcUrl, null))

Tom Nichols

unread,
Sep 21, 2009, 4:10:43 PM9/21/09
to us...@groovy.codehaus.org
Ah, interesting. Thank you for that tip :)

I'm actually using Oracle, not HSQL as my DB... So the connection
process was slightly different but I figured it out.

That's the second time I've been bit by the difference in how Maven
uses classloaders when it adds dependencies to the classpath. But I
suppose I might have been able to use the Class.forName variant that
accepts a classloader as well; that might have worked.

Thanks for the help.

-Tom


2009/9/18 Guillaume Laforge <glaf...@codehaus.org>:

Reply all
Reply to author
Forward
0 new messages