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 your own classes though.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…