title: Dynamic class loading from multiple JARs
body: <p>Consider the following simple method that (attempts to) load all classes of a specific name, residing in a JAR file located in a specified path, i.e.</p>
  
  <pre><code>public static List&lt;Class&lt;?&gt;&gt; getAllClasses(String name, String path)
  {
      File file = new File(path);
  
      try
      {
          URL url = file.toURI().toURL();
  
          URLClassLoader loader = URLClassLoader.newInstance(new URL[] {url});
  
          JarFile jar = new JarFile(file);
  
          Enumeration&lt;JarEntry&gt; entries = jar.entries();
  
          Class&lt;?&gt; type;
  
          String elementName;
  
          List&lt;Class&lt;?&gt;&gt; classList = new ArrayList&lt;Class&lt;?&gt;&gt;();
  
          while (entries.hasMoreElements())
          {
              elementName = entries.nextElement().getName();
  
              if (elementName.equals(name))
              {
                  try
                  {
                      type = loader.loadClass(elementName);
                      classList.add(type);
                  }
                  catch (Exception e)
                  {
                  }
              }
          }
  
          return classList;
      }
      catch (Exception e)
      {
      }
  
      return null;
  }
  </code></pre>
  
  <p>If there are more than 1 JARs in the path, each of which has at least one class with an identical canonical name with an already loaded class, e.g. <code>org.whatever.MyClass</code>, is there any way, without customized class loaders, to load all <code>org.whatever.MyClass</code> classes?</p>