title: A custom system class loader is not used by all classes
body: <p>I'm implementing a feature that requires passing dynamically generated types (in binary representation, serialised with Kryo) between several instances of JVM (over the network). In order to properly resolve what types are loaded and what are not I use a custom system class loader (passed as java <code>-Djava.system.class.loader</code> parameter), which is used by other dynamically created class loaders as a parent. This custom system class loader knows of its children and in case it cannot find a class these derived class loaders can be asked if they have it (this is a reverse to the standard hierarchical structure of class loaders).</p>
  
  <p>These dynamically generated types get transferred and loaded between different JVMs perfectly fine. The problem arises when I try to deserialise an instance of some type (a corresponding class is loaded from disc and is identical for all JMVs) that references one of the dynamically generated types -- ClassNotFoundException is raised by an instance of Kryo, which tries to <code>readClass</code> by name of the dynamically generated type. </p>
  
  <p>Inside method <code>readClass</code> there a call to <code>Class.forName</code>, which in turn does not use the specified custom class loader (that knows of all dynamically generated types) and instead uses sun.misc.Launcher$AppClassLoader instance.</p>
  
  <p>Is it possible to specify a custom system-wide class loader, so that all classes are loaded with it in order to avoid the described problem?</p>
  
  <hr>
  
  <p><strong>Update</strong></p>
  
  <p>Further analysis revealed that <code>ClassLoader.getSystemClassLoader()</code> actually returns the specified custom system class loader. Fortunately, the Kryo library supports setting of a custom class loader specifically for loading classes upon deserialisation. These two facts formed the basis of a solution to the described problem.</p>