参考springboot 

Class<?> deduceMainApplicationClass() {
    try {
        StackTraceElement[] stackTrace = new RuntimeException().getStackTrace();
        for (StackTraceElement stackTraceElement : stackTrace) {
            if ("main".equals(stackTraceElement.getMethodName())) {
                return Class.forName(stackTraceElement.getClassName());
            }
        }
    }
    catch (ClassNotFoundException ex) {
        // Swallow and continue
    }
    return null;
}

 

java如何寻找main函数对应的类

 

相关文章:

  • 2021-10-27
  • 2022-01-09
  • 2022-12-23
  • 2021-11-29
  • 2021-12-18
  • 2022-12-23
  • 2021-12-03
  • 2021-11-29
猜你喜欢
  • 2021-06-29
  • 2021-11-18
  • 2022-12-23
  • 2021-12-28
  • 2022-01-08
  • 2021-09-20
相关资源
相似解决方案