title: load class not in classpath dynamically in web application - without using custom classloader
body: <p>I am developing a web application.</p>
  
  <ol>
  <li>The web application generates java classes on the fly. For example it generates class <code>com.people.Customer.java</code></li>
  <li>In my code, I dynamically compile this to get com.people.Customer.class and store in some directory say <code>repository/com/people/Customer.class</code> which is not on the classpath of my application server.My application server(I am using WebSphere Application Server/Apache Tomcat etc) picks up the classes from the <code>WEB-INF/classes</code> directory. The Classloader would use this to load the classes.</li>
  <li>After compilation I need to load this class so that it becomes accessible to other classes using it after its creation.</li>
  <li>When I use <code>Thread.currentThread().getContextClassLoader().loadClass(com.people.Customer)</code> obviously the Classloader is not able to load the class, since its not on the classpath(not in <code>WEB-INF/classes</code>). Due to similar reasons, <code>getResource(..)</code> or <code>getResourceAsStream(..)</code> also does not work.</li>
  </ol>
  
  <p>I need a way to :</p>
  
  <p>Read the class <code>Customer.class</code> maybe as a stream (or any other way would do) and then load it. Following are the constraints:</p>
  
  <ol>
  <li>I cannot add the repository folder to the <code>WEB-INF/classes</code> folder.</li>
  <li>I cannot create a new Custom ClassLoader. If I create a new ClassLoader and this loads the class, it will not be accessible to its parent ClassLoader.</li>
  </ol>
  
  <p>Is there any way of achieving this?</p>
  
  <p>If not this, in the worse case, is there a way of overriding the default class loader with a custom class loader for web applications the same classloader should be used to load applications throughout entire lifecycle of my web application.</p>
  
  <p>Appreciate any solution :) </p>