5

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

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.

EDIT: 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()); 
2
  • And how are these jars added? Do you use an existing mechanism? Commented Jul 9, 2013 at 9:59
  • Added an edit to my question... Commented Jul 9, 2013 at 10:03

1 Answer 1

5

Maybe you need to use the relevant classloader as well,

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

Or just:

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

Check it out in the documentation.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.