"System Classloader"

403 views
Skip to first unread message

David P

unread,
Nov 29, 2011, 2:43:41 PM11/29/11
to simple-build-tool
Hi all,

In my project I'm using a library that makes use of it's own custom
classloader. When I try to run tests that make use of this library
under sbt, I get a ClassNotFoundException for a class that I know is
on my classpath. In my code, I can import it, instantiate it, etc....
But the custom classloader can't seem to find it at all.

I ran across the same problem when I was using Maven, but I was able
to get around it by setting "useSystemClassloader" to true in the
surefire plugin. I've been searching sbt docs for a while now, trying
to figure out if I can do the same thing, but I haven't seen anything
yet.

I'm using SBT 0.10.1

Thanks,
David

Jason Zaugg

unread,
Nov 29, 2011, 4:05:07 PM11/29/11
to simple-b...@googlegroups.com
(This advice is based on SBT 0.11.x, but should also apply to 0.10.1)

SBT allows you to customise the classloader used during test execution. Here's the default setup [1] [2] [3]

SBT currently only supports test execution in-process. Maven supports forking tests in a child process, and allows the classpath of that process to be setup either with the system classloader or via an isolated classloader [4]. Some poorly behaved libraries call ClassLoader.getSystemClassloader. You won't be able to accomodate this in your SBT test execution.

It will probably work under the `run` task, which does support forking [5], with this setting:

  fork in run := true

What particular library are you fighting with?

-jason


Doug Tangren

unread,
Nov 29, 2011, 4:07:54 PM11/29/11
to simple-b...@googlegroups.com
I had a similar issue recently when using jerkson deserialization which requires access to case class picked signatures. While my code complied fine, I ran into the same cnf exceptions at runtime.

Here is my workaround

https://github.com/softprops/ls/blob/master/plugin/src/main/scala/classloaders.scala#L4-14

-Doug Tangren
http://lessis.me

David P

unread,
Nov 29, 2011, 4:51:56 PM11/29/11
to simple-build-tool
Thanks guys. I didn't realize that sbt didn't support forking tests
yet.. I did try putting "fork in Test := true" earlier. While it
didn't seem to solve the problem, it didn't break anything either.

I'm currently fighting with an internal library at work. I'll see if
the code works in the run task soon.


On Nov 29, 4:07 pm, Doug Tangren <d.tang...@gmail.com> wrote:
> I had a similar issue recently when using jerkson deserialization which
> requires access to case class picked signatures. While my code complied
> fine, I ran into the same cnf exceptions at runtime.
>
> Here is my workaround
>

> https://github.com/softprops/ls/blob/master/plugin/src/main/scala/cla...
>
> -Doug Tangrenhttp://lessis.me

Michael Slinn

unread,
Feb 9, 2012, 1:44:13 AM2/9/12
to simple-b...@googlegroups.com
For Akka futures, which are multi-threaded by nature, would you recommend this setting?
fork in Run := true

See "Configuration for the fork join pool" and "thread-pool-executor" at http://akka.io/docs/akka/snapshot/scala/dispatchers.html#types-of-dispatchers 

Mike
Reply all
Reply to author
Forward
0 new messages