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 way back to the original class.
I've searched System properties and everything that ClassLoader has to offer and come up with nothing. Is this information just not available?
Thanks.
Here's what I'm using, for situations where you don't control the main:
Even if the thread with the main() method has terminated and you are not using the Oracle JVM you can still attempt to get the information from the operating system. The code below obtains the command line used to start the JVM under Linux but you could write a version for Windows, etc. You could then look at the arguments to the JVM to find the application entry point. It might be directly on the command line or you might have look for Main-Class: classname in the manifest of the specified jar. I would first use System.getProperty("sun.java.command") and friends only falling back to this mechanism if necessary.
Try using Thread.getAllStackTraces(). It returns a Map of the stack traces from all running threads, not just the current one.
Given the clarification, I suggest using the "Parameterisation from Above" idiom. You have the information to start with, keep hold of it.
I did put in an RFE 4827318 (six years ago!) for something like this for use with test runners.