There is a way to determine all currently loaded native libraries if you meant that. Already unloaded libraries can't be determined.
Based on the work of Svetlin Nakov (Extract classes loaded in JVM to single JAR) I did a POC which gives you the names of the loaded native libraries from the application classloader and the classloader of the current class.
First the simplified version with no bu....it exception handling, nice error messages, javadoc, ....
Get the private field in which the class loader stores the already loaded libraries via reflection
public class ClassScope {
private static final java.lang.reflect.Field LIBRARIES;
static {
LIBRARIES = ClassLoader.class.getDeclaredField("loadedLibraryNames");
LIBRARIES.setAccessible(true);
}
public static String[] getLoadedLibraries(final ClassLoader loader) {
final Vector<String> libraries = (Vector<String>) LIBRARIES.get(loader);
return libraries.toArray(new String[] {});
}
}
Call the above like this
final String[] libraries = ClassScope.getLoadedClasses(ClassLoader.getSystemClassLoader()); //MyClassName.class.getClassLoader()
And voilá libraries
holds the names of the loaded native libraries.
Get the full source code from here
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…