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.