I am not sure if this will really answer your question, but it may provide some 
info you can use.

I ran into similar issues with unit tests and actually I think that it is also 
not possible to load the same .dll from even different jvm instances if I 
recall correctly as this was a while ago.

The solution that I ended up using at the time which may be somewhat of a hack 
but not by much imho was to proxy the loadLibrary and have each instance create 
a temp file copy of the .dll.

Not sure if something along those lines could work in your case, it would sound 
to me like just a  matter of being able to specify the .dll filename somewhere 
along the way if you choose this approach...


On Jul 20, 2011, at 1:02 AM, Thomas Fuchs <[email protected]> wrote:

> Hi all,
>  
> I'm facing a problem using Gradle to use groovy.sql.Sql in one task
> and hibernateTools in another task in the same invocation of gradle.
>  
> I'm using MsSqlServer with integratedSecurity, so for creating the
> connection the dll "sqljdbc_auth.dll" is needed.
>  
> This means sqlTask uses the groovy classloader to load the
> driver which loads sqljdbc_auth.dll and
> hibernateToolTask uses AntClassLoader to load the same
> dll. This is not possible in one JVM. A dll can only be loaded
> by one classloader.
>  
> The error I see is: "Failed to load the sqljdbc_auth.dll."
> The real cause is only viewable within the debugger:
> "Native Library already loaded in another classloader"
>  
> Every task works perfectly if I remove the dependency
> from hibernateToolTask to sqlTask and use gradle to invoke it single:
> gradle sqlTask
> gradle hibernateToolTask
>  
> Both together
> gradle hibernateToolTask sqlTask
> result in the error.
>  
> Is there a way to resolve this issue?
>  
> Here are the two tasks:
>  
> task sqlTask() << {
>  URLClassLoader loader = GroovyObject.class.classLoader
>  configurations.driver.each {File file -> loader.addURL(file.toURL())}
>  Class driver = loader.loadClass(dbDriver)
>  Sql sql = Sql.newInstance(dbUrl)
>  logger.info("Using Catalog: ${sql.getConnection().getCatalog()}")
>  sql.eachRow('select * from raw.akte') { row ->
>     println "${row.id} ($row.value)"
>   }
>   sql.close()
> }
> task hibernateToolTask(dependsOn: sqlTask) << {
>  ant {
>    taskdef(name:'hibernatetool', 
>      classname:'org.hibernate.tool.ant.HibernateToolTask', 
>         classpath: configurations.hibernateGen.asPath)
> 
>   hibernatetool {
>    jdbcconfiguration( propertyfile: "$dirGeneratedResources/db.properties",
>           packagename: mapper.dao',
>         reversestrategy: utils.ExtendDelegatingReverseEngineeringStrategy',
>         revengfile: 'src/main/resources/build/hibernate.reveng.xml')
>    hbm2hbmxml (destdir: dirGeneratedHbmRaw)
>    hbm2cfgxml (destdir: dirGeneratedResources)
>    hbm2java   (destdir: dirGeneratedJava, jdk5:'true')
>   }
>  }
> }
> compileJava.dependsOn(hibernateToolTask)
>  
> Environement infos:
> ------------------------------------------------------------
> Gradle 1.0-milestone-3
> ------------------------------------------------------------
> Gradle build time: Monday, 25 April 2011 5:40:11 PM EST
> Groovy: 1.7.10
> Ant: Apache Ant(TM) version 1.8.2 compiled on December 20 2010
> Ivy: 2.2.0
> JVM: 1.6.0_16 (Sun Microsystems Inc. 14.2-b01)
> OS: Windows 7 6.1 x86
> Anyone got any ideas?
> Thanks very much in advance for any hints!
> 
> Thomas

Reply via email to