If I know the class, how can I find out which bank it is from?

I can now use clazz.getClassLoader (). getResource (class.getName ()), then tweak the url to get the location of the jar file, but I really want to know if there is a better way to do this.

Is there an API for this? thanks.

+4
source share
1 answer

If your class is called Foo

URL classLocation = Foo.class.getProtectionDomain().getCodeSource().getLocation() 

classLocation will contain the URL from which the class was loaded. Either the folder for a separate class, or jar / zip.

+4
source

Source: https://habr.com/ru/post/1299926/


All Articles