content: 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<Class<?>> findClasses(String packageName) {
          List<Class<?>> 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;
      }
  }
  