當前位置:
首頁 >
java如何寻找main函数对应的类
發布時間:2025/3/8
31
豆豆
生活随笔
收集整理的這篇文章主要介紹了
java如何寻找main函数对应的类
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
參考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; }?
?
轉載于:https://www.cnblogs.com/hujunzheng/p/8333955.html
總結
以上是生活随笔為你收集整理的java如何寻找main函数对应的类的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: redis分布式锁小试
- 下一篇: sublime text学习