سؤال

I am using java instrumentation. Given the class name (which is being instrumented), how can I know the jar file it is in?

هل كانت مفيدة؟

المحلول

The following code should work. I tried it with a single jar and it gave me the jar path:

new File(Test.class.getProtectionDomain().getCodeSource().getLocation().getFile())

Just replace Test by your class name.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top