title: URLClassLoader keeps throwing ClassNotFoundException. What am I doing wrong?
body: <p>I'm working on a university java project that requires me to implement a simple plugin architecture. A main application in Project A would have to load plugins from a specified directory located in another project B. After having done some research on the topic (including stackoverflow), I decided to go with URLClassLoader to load the classes which I might then instatiate. Project B references Project A and all plugins extend a common plugin class (might as well be an interface but should not make any difference). This is what I have got so far:</p>
  
  <p>The source for the plugin class I try to load:</p>
  
  <pre><code>package plugin;
  
  import de.uks.student.pluginpattern.model.EditorPlugin;
  
  public class Circle extends EditorPlugin
  {
     @Override
     public void init()
     {
  
     }
  }
  </code></pre>
  
  <p>and the code that is supposed to load the class:</p>
  
  <pre><code>public void init(String[] args)
     {
        editorPane = new EditorPane().withWidth(500).withHeight(500);
        toolBar = new ToolBar();
        plugins = new EditorPluginSet();
        // load plugins
        File pluginDir = new File(PLUGIN_PATH);
        if (!pluginDir.exists())
        {
           System.err.println("Plugin path not found!!");
           return;
        }
        String[] plugins = pluginDir.list();
        if (plugins == null)
        {
           System.err.println("Plugin path points to a file!!");
           return;
        }
  
        for (String pluginString : plugins)
        {
           for (String argString : args)
           {
              if (pluginString.contains(argString))
              {
                 System.out.println("Loading plugin from " + pluginString);
                 File pluginFile = new File(PLUGIN_PATH + "/");
                 // as getAbsolutePath embeds the relative path ... /../pluginProject ...
                 // which may not be processed correctly by the OS (Windows at least),
                 // we correct the path manually (just to be on the safe side)
                 String absolutePath = pluginFile.getAbsolutePath();
                 String[] split = absolutePath.split("\\\\");
  
                 List&lt;String&gt; splitsimpleList = Arrays.asList(split);
                 ArrayList&lt;String&gt; splitList = new ArrayList&lt;&gt;(splitsimpleList);
                 for (int i = 0; i &lt; splitList.size() - 1; ++i)
                 {
                    if (splitList.get(i + 1).equals(".."))
                    {
                       splitList.remove(i);
                       splitList.remove(i);
                       break;
                    }
                 }
                 StringBuilder b = new StringBuilder();
                 for (String string : splitList)
                 {
                    b.append(string);
                    b.append("/");
                 }
                 File pluginFileForRealThisTime = new File(b.toString());
  
                 URL pluginURL = null;
                 try
                 {
                    pluginURL = pluginFileForRealThisTime.toURI().toURL();
                 } catch (MalformedURLException e)
                 {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                 }
                 URL[] urls = {pluginURL};
                 ClassLoader parentClassLoader = this.getClass().getClassLoader();
                 URLClassLoader uLoader = new URLClassLoader(urls, parentClassLoader);
                 Class&lt;?&gt; pluginClass = null;
                 try
                 {
                    String className = "plugin." + argString;
                    pluginClass = uLoader.loadClass(className);
                 } catch (ClassNotFoundException e)
                 {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                 }
              }
           }
        }
     }
  </code></pre>
  
  <p>Now I always end up with a ClassNotFoundException:</p>
  
  <blockquote>
    <p>java.lang.ClassNotFoundException: plugin.Circle   at
    java.net.URLClassLoader$1.run(Unknown Source)     at
    java.net.URLClassLoader$1.run(Unknown Source)     at
    java.security.AccessController.doPrivileged(Native Method)    at
    java.net.URLClassLoader.findClass(Unknown Source)     at
    java.lang.ClassLoader.loadClass(Unknown Source)   at
    java.lang.ClassLoader.loadClass(Unknown Source)   at
    de.uks.student.pluginpattern.model.EditorSystem.init(EditorSystem.java:412)
      at
    de.uks.student.pluginpattern.EditorSystem.main(EditorSystem.java:13)</p>
  </blockquote>
  
  <p>I've already checked that</p>
  
  <ul>
  <li>the generated URL can be correctly resolved by any web browser and Windows Explorer.</li>
  <li>Circle.class has been built and is present in the directory referenced by the used URL</li>
  <li>className resolves to "plugin.Circle" which should be the correct binary name to use</li>
  <li>removing inheritance from plugin.Circle does not make any difference.</li>
  </ul>
  
  <p>I've pretty much run out of ideas on what else to try. What am I doing wrong?</p>