jeudi 5 mars 2020

Scanner TypeAnnotationsScanner was not configured, when used from a referenced library

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)

Any pointers?





Aucun commentaire:

Enregistrer un commentaire