Get name of executable jar from within main() method [duplicate]
Here you go: new java.io.File(SomeClassInYourJar.class.getProtectionDomain() .getCodeSource() .getLocation() .getPath()) .getName() Edit: I saw your comment about getSourceCode API. Well, this is probably the best you can do in Java. About getCodeSource() returning null, I think it mainly happens on classes in java.lang.* and other special classes for which the source location is “hidden”. Should work for … Read more