Why do you need this?
# announcements
k
Why do you need this?
d
The information is definitely in the class file (https://docs.oracle.com/javase/specs/jvms/se10/html/jvms-4.html#jvms-4.7.10). However I don't think you can get at it using reflection or similar terms. You'd have to get the raw class file bytes and read it using something like ASM... Not very practical.
c
thanks. i could just read the class file
n
try this:
val f = File(MyClass::class.java!!.getProtectionDomain().getCodeSource().getLocation().getPath())
e
yeah, i was pretty sure that was in there somewhere.
c
oh wow, thanks. i got it working by getting the path from the classfile, and then the filename from the stacktrace element
but that is much simpler
@Nikky i already do this, this gives me the path of the class file
anyway i got it working by taking the name from the stack trace element, so thanks everybody
f
you can get it from the
.class
file as others mentioned above, but you'll have to either parse the .class file yourself or use a library that does it for you (Apache BCEL has that, I'm sure most other bytecode manipulation libs also do). BCEL implementation is here if you're curious : https://github.com/apache/commons-bcel/blob/trunk/src/main/java/org/apache/bcel/classfile/ClassParser.java
c
interesting!