如何使用Google反射库扫描运行时加载的JAR? [英] How to scan JAR's, which are loaded at runtime, with Google reflections library?

查看:146
本文介绍了如何使用Google反射库扫描运行时加载的JAR?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

Is there a solution to configure the reflection library so that it scans also JAR's which are added at runtime with URLClassLoader?

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

For now, reflections just scans the URLs in the ClassLoader. This is the configuration which I am using now:

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

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

I couldn't find any hints in the doc of the reflections library.

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

This is how I load the jar File:

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


推荐答案

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

Maybe you need to use the relevant classloader as well,

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

或者只是:

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

文档中查看

这篇关于如何使用Google反射库扫描运行时加载的JAR?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆