0

I have created a new class with the following code:

//...name and fields etc
.make()
.load(NetworkClassManager.class.getClassLoader())
.getLoaded();

Which has created my class called TestNetwork_ND, but when I try access it using:

NetworkClassManager.class.getClassLoader().loadClass("TestNetwork_ND")

I get the following error:

java.lang.ClassNotFoundException: TestNetwork_ND

How can I load it onto the classpath properly so that I can access it in the above way?

Shaun Wild
  • 1,237
  • 3
  • 17
  • 34

1 Answers1

0

I had to inject the class.

.make()
.load(NetworkClassManager.class.getClassLoader(), ClassLoadingStrategy.Default.INJECTION)
            .getLoaded();

Using the ClassLoadingStrategy.Default.INJECTION, loading strategy fixed it for me.

Shaun Wild
  • 1,237
  • 3
  • 17
  • 34
  • 1
    The default strategy is creating a wrapper class loader. The strategy you are now using is relying on sun.misc.Unsafe but as of Java 9, there is a safe alternative with the ClassLoadingStrategy.UsingLookup. – Rafael Winterhalter Mar 08 '19 at 07:18
  • I shall remember this when/if I migrate to Java 9 :) – Shaun Wild Mar 08 '19 at 16:43