title: How to get all classes names in a package?
body: <p>So I have a package that has classes that extend JPanel and I want to add them as tabs dynamically. At the beginning I used a factory and I registered all the classes in it and it worked, but now I want load all the classes in the package without knowing their names. I've tried several things including <a href="http://code.google.com/p/reflections/" rel="noreferrer">Reflections library</a> (which I found very confusing) and I couldn't get them to work. I appreciate any help.</p>
  
  <p>Here's one of my trials:</p>
  
  <pre><code>public static void registerTab() {
      String pkg = TabA.class.getPackage().getName();
      String relPath = pkg.replace('.', '/');
  
      URL resource = ClassLoader.getSystemClassLoader().getResource(relPath);
      if (resource == null) {
          throw new RuntimeException("Unexpected problem: No resource for "
                  + relPath);
      }
  
      File f = new File(resource.getPath());
  
      String[] files = f.list();
  
      for (int i = 0; i &lt; files.length; i++) {
  
          String fileName = files[i];
          String className = null;
          String fileNm = null;
  
          if (fileName.endsWith(".class")) {
  
              fileNm = fileName.substring(0, fileName.length() - 6);
              className = pkg + '.' + fileNm;
          }
  
          if (className != null) {
  
              if (!tabClasses.containsKey(className))
                  tabClasses.put(fileNm, className);
          }
      }
  }
  </code></pre>