String (ModuleChunk chunk, String agentClassName) { Collection<File> files = ProjectPaths.getCompilationClasspathFiles(chunk, chunk.containsTests(), false, false); URL[] urls = new URL[files.size()]; int i = 0; for (File file : files) { try { urls[i] = file.toURI().toURL(); ++i; } catch (MalformedURLException e) { LOG.warn("Malformed dependency: " + file); } } try (URLClassLoader dependenciesLoader = new URLClassLoader(urls, StandardJavaFileManager.class.getClassLoader())) { Class<?> agentClass = Class.forName(agentClassName, false, dependenciesLoader); URL agentUrl = agentClass.getProtectionDomain().getCodeSource().getLocation(); File agentClassFile = new File(URLDecoder.decode(agentUrl.getPath(), StandardCharsets.UTF_8)); return agentClassFile.getAbsolutePath(); } catch (IOException | ClassNotFoundException e) { throw new RuntimeException(e); } }