I have a class which uses
org.reflections.Reflections to get annotations in classes in the class path.
When i use it in the same project everything works fine, but when i export it as a JAR and refer it in a different class i get the below execption:
Exception in thread "main" org.reflections.ReflectionsException: Scanner TypeAnnotationsScanner was not configured at org.reflections.Store.get(Store.java:39) at org.reflections.Store.get(Store.java:61) at org.reflections.Store.get(Store.java:46) at org.reflections.Reflections.getTypesAnnotatedWith(Reflections.java:429)
Here is the code snippet:
System.out.println("Package to Scan: "+getPackageName()); final Reflections reflections = new Reflections(getPackageName(), new TypeAnnotationsScanner()); final Set<Class<?>> handlerClasses = reflections.getTypesAnnotatedWith(HandlerMapping.class,true);
I do provide a
TypeAnnotationsScanner object, but still issue persists.
Note: It does not work only when above code is referred as a jar. (I created a fat jar using maven-assembly plugin)
Maybe not the type of answer one wants to hear but
0.9.12 contains a bug described here: https://github.com/ronmamo/reflections/issues/273
The bugfix has been provided in this PR (not merged yet): https://github.com/ronmamo/reflections/pull/278
The major difference between version
0.9.12 is that in
0.9.12 Guava dependency was removed in favor of Java 8 Streams API.
If you need to include this dependency without Guava transitive dependency, you may look at the next project: https://github.com/aschoerk/reflections8
Currently, the latest available version of
reflections8 is now considered to be obsolete due to
0.9.12 release of
reflections but their version
0.11.7 doesn’t contain this bug and this version doesn’t depend on Guava. So, a possible solution would be to switch to