Your code might work, but it doesn't solve my real problem..... Let me give a little context. This example is me breaking down a complex problem to it's simplest form. I have legacy java code that I am calling from a gradle plugin. This legacy code is widely used across 1000s of people and dozens of projects, so I would like to avoid modifying it. My unit tests on the gradle plugin all work fine, but when I call my plugin task from gradle itself I get this ClassNotFoundException from deep inside this legacy code. I found this odd, so I tried all sorts of different methods to figure out the core problem. Basically I have it down to this snippet of code: http://pastie.org/1900695
On Sat, May 14, 2011 at 9:46 AM, Marco Hunsicker <[email protected]> wrote: >> let me clean it up. You should be able to copy paste this directly to >> your >> system and try it. For some reason, the class isn't found. I tried this >> with the Base64 example Roger posted and was able to get a Base64 class >> lookup (Class.forName) to work properly. So it seems there is something >> odd >> about the Xerces class.... >> >> task hello { >> doLast { >> println 'Hello world!' >> Class testClass = >> Class.forName("org.apache.xerces.jaxp.DocumentBuilderFactoryImpl") >> assert testClass: >> "org.apache.xerces.jaxp.DocumentBuilderFactoryImpl >> not found" >> println "found" >> } >> } > > Have you tried using the context class loader? Might be worth a try: > > Thread.currentThread().getContextClassLoader().loadClass("..."); > > > Cheers, > > Marco > > > --------------------------------------------------------------------- > 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
