Allow manual scanning of only rt.jar
(thanks to @jechlin for the request).
This code will locate and scan rt.jar
:
String rtJarPath = null;
for (URI uri : new ClassGraph().enableSystemJarsAndModules().getClasspathURIs()) {
if (uri.getPath().endsWith("/rt.jar")) {
rtJarPath = uri.getPath();
break;
}
}
if (rtJarPath == null) {
// rt.jar will not be found on JDK 9+ -- you need to scan system modules instead
throw new RuntimeException("rt.jar not found");
}
try (ScanResult scanResult = new ClassGraph().overrideClasspath(rtJarPath)
.enableSystemJarsAndModules().enableAllInfo().scan()) {
System.out.println("Found " + scanResult.getAllClasses().size() + " classes in rt.jar");
}