MKo*_*sch 4 java runtime classloader reflections
是否有配置反射库的解决方案,以便它也扫描在运行时使用 URLClassLoader 添加的 JAR?
现在,反射只是扫描 ClassLoader 中的 URL。这是我现在使用的配置:
Reflections reflections = new Reflections(new ConfigurationBuilder().setUrls(ClasspathHelper.forClassLoader()));
Run Code Online (Sandbox Code Playgroud)
我在反射库的文档中找不到任何提示。
编辑: 这就是我加载 jar 文件的方式:
File f = new File("C:/Users/mkorsch/Desktop/test-reflections.jar");
URLClassLoader urlCl = new URLClassLoader(new URL[] {f.toURI().toURL()},System.class.getClassLoader());
Run Code Online (Sandbox Code Playgroud)
也许您还需要使用相关的类加载器,
Reflections reflections = new Reflections(new ConfigurationBuilder().setUrls(ClasspathHelper.forPackage("my.package", myClassLoader)).addClassLoader(myClassLoader));
Run Code Online (Sandbox Code Playgroud)
要不就:
new Reflections("my.package", myClassLoader, scanners, ...)
Run Code Online (Sandbox Code Playgroud)
在文档中查看它。