All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.taobao.arthas.grpc.server.utils.ReflectUtil Maven / Gradle / Ivy

The newest version!
package com.taobao.arthas.grpc.server.utils;

import java.io.File;
import java.net.URL;
import java.util.ArrayList;
import java.util.List;

/**
 * @author: FengYe
 * @date: 2024/9/6 02:20
 * @description: ReflectUtil
 */
public class ReflectUtil {
    public static List> findClasses(String packageName) {
        List> classes = new ArrayList<>();
        String path = packageName.replace('.', '/');
        try {
            URL resource = Thread.currentThread().getContextClassLoader().getResource(path);
            if (resource != null) {
                File directory = new File(resource.toURI());
                if (directory.exists()) {
                    for (File file : directory.listFiles()) {
                        if (file.isFile() && file.getName().endsWith(".class")) {
                            String className = packageName + '.' + file.getName().replace(".class", "");
                            classes.add(Class.forName(className));
                        }
                    }
                }
            }
        } catch (Exception e) {

        }
        return classes;
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy