private void addAllFilesInDirectory(
        final Path directory,
        final Set<Class<?>> allClasses,
        final String packageName,
        final boolean recursive
    ) {
        // Get the list of the files contained in the package
        try (DirectoryStream<Path> stream = Files.newDirectoryStream(directory, getFileFilter())) {
            for (Path file : stream) {
                // we are only interested in .class files
                if (Files.isDirectory(file)) {
                    if (recursive) {
                        String dirName = String.valueOf(file.getFileName());
                        if (dirName.endsWith("/")) {
                            // Seems java 8 adds "/" at the end of directory name when
                            // reading from jar filesystem. We need to remove it. - Ali-RS 2023-1-5
                            dirName = dirName.substring(0, dirName.length() - 1);
                        }
                        addAllFilesInDirectory(file, allClasses, packageName + dirName + ".", true);
                    }
                } else {
                    Class<?> result = load(packageName + file.getFileName());
                    if (result != null && !allClasses.contains(result)) {
                        allClasses.add(result);
                    }
                }
            }
        } catch (IOException ex) {
            logger.log(Level.SEVERE, "Could not search the folder!", ex);
        }
    }
Used to descent in directories, loads classes via {@link #load}

@param directory
           where to search for class files
@param allClasses
           add loaded classes to this collection
@param packageName
           current package name for the given directory
@param recursive
           true to descend into subdirectories
jme3-examples/src/main/java/jme3test/TestChooser.java