public static List<String> discoverLocalApplicationClasses(Class<?> mainClass) {
List<String> localClasses = new ArrayList<>();
try {
// Grab the physical root location where your main class was loaded from
java.security.ProtectionDomain pd = mainClass.getProtectionDomain();
java.security.CodeSource cs = pd.getCodeSource();
if (cs != null && cs.getLocation() != null) {
File rootFile = new File(cs.getLocation().toURI());
// 1. LOCAL DEVELOPMENT: Root is a loose classes folder
if (rootFile.isDirectory()) {
System.out.println("[PROFILER-AGENT] Root discovered (Directory): " + rootFile.getAbsolutePath());
scanDirectoryForClasses(rootFile, "", localClasses);
}
// 2. LINUX DEPLOYMENT: Root is the packaged application JAR
else if (rootFile.isFile() && rootFile.getName().endsWith(".jar")) {
System.out.println("[PROFILER-AGENT] Root discovered (JAR File): " + rootFile.getAbsolutePath());
scanJarForClasses(rootFile, localClasses);
}
}
} catch (Exception e) {
System.err.println("[PROFILER-AGENT] Failed to auto-discover classes via ProtectionDomain: " + e.getMessage());
}
System.out.println("[PROFILER-AGENT] Auto-discovered " + localClasses.size() + " target application classes.");
return localClasses;
}
For further actions, you may consider blocking this person and/or reporting abuse
Top comments (0)