How to determine main class at runtime in threaded java application?

后端 未结 10 1023
野的像风
野的像风 2021-01-01 13:37

I want to determine the class name where my application started, the one with the main() method, at runtime, but I\'m in another thread and my stacktrace doesn\'t go all the

10条回答
  •  猫巷女王i
    2021-01-01 14:38

    See the comments on link given by Tom Hawtin. A solution is these days is (Oracle JVM only):

    public static String getMainClassAndArgs() {
        return System.getProperty("sun.java.command"); // like "org.x.y.Main arg1 arg2"
    }
    

    Tested only with Oracle Java 7. More information about special cases: http://bugs.java.com/view_bug.do?bug_id=4827318

提交回复
热议问题