I trying to find out jar name for using class name . Assume I having class Name as "Socket" or " LinkedList" as String. So I want know how to find out , which jar it's belong',s. I am trying to find out by this way
public static String getModuleName(Class classname) {
String modulename = null;
URL resource = classname.getResource('/' + classname.getName().replace('.', '/') + ".class");
System.out.println(resource.getPath());
String[] split = resource.getFile().split("/");
for (String string : split) {
if (string.contains("jar")) {
modulename = string.replace("!", "");
}
}
return modulename;
}
In this method If I am passing
Class class1 = String.class;
System.out.println(getModuleName(class1));
It's Giving Jar name but it's giving jar name but for some requirement , I don't have like "String.class" but Only string "String" . From this string how ton find out which jar it's belongs.
Thanks