Java – how do I get an object / class to tell me which jar file it comes from

In eclipse, an impossible class is being loaded In debug mode, I can pause it and see the call to class A.B.C, but class A.B.C should exist anywhere because it has been renamed My assumption is that an old jar file is called... But I can't find it So how to find the jar file where the A.B.C class is located in debugging mode in eclipse? Get the object and tell me my own jar file through eclipse menu options or through Java and use reflection

thank you.

Solution

You can use the classloader to retrieve the URL of the resource This also applies to classes To get Java Location of lang.string class:

X.class.getClassLoader().getResource("java/lang/String.class");

Output:

jar:file:/C:/Program%20Files/Java/jdk1.6.0_17/jre/lib/rt.jar!/java/lang/String.class
The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>