title: Reflection Proxy- Visibility from class loader problem
body: <p>I'm attempting to:<br>
  1) Load an interface and implementation class from a given file location<br>
  2) Create a Proxy object with reflection that matches the interface, and directs all calls to the implementation class  </p>
  
  <p>This is later used for testing purposes using JUnit.</p>
  
  <p><strong>The Problem:</strong><br>
  However, I seem to be having problems when I try to create the proxy object. I get the exception:  </p>
  
  <pre><code>java.lang.IllegalArgumentException: interface Testing.Testable is not visible from class loader
  ...at Core.ProxyFactory.createProxy(ProxyFactory.java:26)
  </code></pre>
  
  <p>The line in question is as follows:</p>
  
  <pre><code>Object obj = Proxy.newProxyInstance(implementationClass.getClassLoader(), new Class[]{interfaceClass}, forwarder);
  </code></pre>
  
  <p><strong>Class loading the right way?</strong><br>
  I am loading the classes that I need using a URLClassLoader. The snippet for this is as follows:</p>
  
  <pre><code>URL url = new File(path).toURI().toURL();
  URL[] urlList = {url};
  // Create loader and load
  ClassLoader classLoader = new URLClassLoader(urlList);
  Class loadedClass = classLoader.loadClass (classname);
  return loadedClass;
  </code></pre>
  
  <p>However, is this correct? This snippet gets repeated for each class file, and so I believe each time a new class loader is created. Could this be causing my problem? How can I resolve this?</p>
  
  <p><em>Thanks in advance for any help you can give</em></p>