$0 (Program Name) in Java? Discover main class?

前端 未结 8 950
死守一世寂寞
死守一世寂寞 2020-12-03 00:23

Is there a way to find the name of the program that is running in Java? The class of the main method would be good enough.

8条回答
  •  春和景丽
    2020-12-03 01:17

    To expand on @jodonnell you can also get all stack traces in the system using Thread.getAllStackTraces(). From this you can search all the stack traces for the main Thread to determine what the main class is. This will work even if your class is not running in the main thread.

提交回复
热议问题