private Set<Class<?>> findClassesFromJar(String jarFileName, String packageName,
    boolean proceedOnExceptions) throws IOException, ClassNotFoundException, LinkageError {
    JarInputStream jarFile;
    try {
      jarFile = new JarInputStream(new FileInputStream(jarFileName));
    } catch (IOException ioEx) {
      LOG.warn("Failed to look for classes in " + jarFileName + ": " + ioEx);
      throw ioEx;
    }

    Set<Class<?>> classes = new HashSet<>();
    JarEntry entry;
    try {
      while (true) {
        try {
          entry = jarFile.getNextJarEntry();
        } catch (IOException ioEx) {
          if (!proceedOnExceptions) {
            throw ioEx;
          }
          LOG.warn("Failed to get next entry from " + jarFileName + ": " + ioEx);
          break;
        }
        if (entry == null) {
          break; // loop termination condition
        }

        String className = entry.getName();
        if (!className.endsWith(CLASS_EXT)) {
          continue;
        }
        int ix = className.lastIndexOf('/');
        String fileName = (ix >= 0) ? className.substring(ix + 1) : className;
        if (
          null != this.fileNameFilter && !this.fileNameFilter.isCandidateFile(fileName, className)
        ) {
          continue;
        }
        className =
          className.substring(0, className.length() - CLASS_EXT.length()).replace('/', '.');
        if (!className.startsWith(packageName)) {
          continue;
        }
        Class<?> c = makeClass(className, proceedOnExceptions);
        if (c != null) {
          if (!classes.add(c)) {
            LOG.warn("Ignoring duplicate class " + className);
          }
        }
      }
      return classes;
    } finally {
      jarFile.close();
    }
  }
Finds the classes in a package and nested packages.
@param packageName         package names
@param proceedOnExceptions whether to ignore exceptions encountered for individual
                           jars/files/classes, and proceed looking for others.
hbase-common/src/test/java/org/apache/hadoop/hbase/ClassFinder.java