SBT plugin development: problem with loading classes via Class.forName, can you help?

200 views
Skip to first unread message

Galder Zamarreño

unread,
Nov 16, 2012, 1:38:51 PM11/16/12
to simple-b...@googlegroups.com
Hi all,

I'm creating an SBT plugin and I'm having some classloading issues running the 'scripted' tests.

The error is (full stacktrace in https://gist.github.com/4089679):
[info] Caused by: java.lang.ClassNotFoundException: Could not find requested class "org.jboss.shrinkwrap.impl.base.ServiceExtensionLoader" in any of the associated ClassLoaders: [sun.misc.Launcher$AppClassLoader@43be2d65]

From the SBT plugin code, I've tried to do this:

Thread.currentThread().getContextClassLoader.loadClass("org.jboss.shrinkwrap.api.ShrinkWrap")

And I get:
[info] java.lang.ClassNotFoundException: org.jboss.shrinkwrap.api.ShrinkWrap

So, it would appear that the dependencies of the libraries are not added to the runtime classloader? Or maybe I'm doing this from the wrong classloader?

What would be the classloader to use here? I know I can configure ShrinkWrap with a classloader, but I've no idea where/how to retrieve it from SBT? I imagine there's some kind of classloader there cos the 1st stacktrace shows org.jboss.shrinkwrap.api classes being run.

I can share SBT plugin code if needed.

On top of this, one final question:
- How can you run scripted tests via a debugger? I've tried add remote debugging options to the SBT command, but it appears that a different JVM instance (forked?) is used for the scripted tests.

Thanks

Galder Zamarreño

unread,
Nov 16, 2012, 2:15:14 PM11/16/12
to simple-b...@googlegroups.com
Aha! This might work....

      val classLoader = classOf[ShrinkWrap].getClassLoader
      classLoader.loadClass("org.jboss.shrinkwrap.api.ShrinkWrap")

The classloader is:
sbt.PluginManagement$PluginClassLoader@2be27046

I'll try to configure ShrinkWrap with that classloader and see if that works (or change the TCCL momentarily...)
Reply all
Reply to author
Forward
0 new messages