开发者

if i know a class, how can i know which jar it is from?

开发者 https://www.devze.com 2022-12-18 22:21 出处:网络
for now i could use c开发者_StackOverflow中文版lazz.getClassLoader().getResource(class.getName()), then i substring the URL to get the jar file\'s location, but i really want to know if there is any b

for now i could use c开发者_StackOverflow中文版lazz.getClassLoader().getResource(class.getName()), then i substring the URL to get the jar file's location, but i really want to know if there is any better way to do it.

is there any API for this? thank you.


If your class is called Foo

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

classLocation will contain the URL where the class was loaded from. Either a folder for a stand alone class or a jar/zip.

0

精彩评论

暂无评论...
验证码 换一张
取 消