Search code examples
javaspringspring-bootdockerreflections

org.reflection.Reflections 0.10.2 fails when running as jar (e.g. in a docker container)


I used org.reflections (latest):

new Reflections("my.package").getSubTypesOf(MyService.class);

It works well running in IntelliJ and returns all implementations of MyService.class.

But running in a docker container, it returns an empty Set.

(Anything else works well in the docker-container)

Any ideas? TIA!


Solution

  • This answer results from the comments ...

    The problem is the following bug/issue:

    https://github.com/ronmamo/reflections/issues/373 - 'Reflections does not detect any classes, if base class (or package prefix) is passed as argument, and application is running as a jar'

    But it works (for me) with the workaround, suggested in the above mentioned issue.

    Reflections reflections = new Reflections(new ConfigurationBuilder().forPackages("my.package"));
    Set<Class<? extends MyService>> classes = reflections.getSubTypesOf(MyService.class);