【问题标题】:How to scan JAR's, which are loaded at runtime, with Google reflections library?如何使用 Google 反射库扫描在运行时加载的 JAR?
【发布时间】:2013-07-09 09:53:41
【问题描述】:

是否有配置反射库的解决方案,以便它也扫描在运行时使用 URLClassLoader 添加的 JAR?

目前,反射只是扫描 ClassLoader 中的 URL。这是我现在使用的配置:

Reflections reflections = new Reflections(new ConfigurationBuilder().setUrls(ClasspathHelper.forClassLoader()));

我在反射库的文档中找不到任何提示。

编辑: 这就是我加载 jar 文件的方式:

File f = new File("C:/Users/mkorsch/Desktop/test-reflections.jar");
URLClassLoader urlCl = new URLClassLoader(new URL[] {f.toURI().toURL()},System.class.getClassLoader());

【问题讨论】:

  • 这些罐子是如何添加的?您是否使用现有机制?
  • 对我的问题添加了编辑...

标签: java runtime classloader reflections


【解决方案1】:

也许您还需要使用相关的类加载器,

Reflections reflections = new Reflections(new ConfigurationBuilder().setUrls(ClasspathHelper.forPackage("my.package", myClassLoader)).addClassLoader(myClassLoader));

或者只是:

new Reflections("my.package", myClassLoader, scanners, ...)

documentation 中查看。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-01-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-07-24
    相关资源
    最近更新 更多