4

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!

t777
  • 3,099
  • 8
  • 35
  • 53
  • It works well with `org.reflections` version `0.9.12`, but not with latest `0.10.2`. – t777 Jan 16 '22 at 00:43
  • I think the reason is https://github.com/ronmamo/reflections/issues/373 - So I have to wait for the next release ... Until than, I will use `0.9.12`. – t777 Jan 16 '22 at 00:45
  • Can you use the work-around given in the issue ticket you reference? – CryptoFool Jan 16 '22 at 00:50
  • @CryptoFool Sorry. I had overlooked the workaround. With that it works. Thanks for the hint. :) – t777 Jan 16 '22 at 00:53

1 Answers1

9

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);
t777
  • 3,099
  • 8
  • 35
  • 53
  • I would suggest that you state in your answer that the problem has nothing to do with Docker but rather is a function of if the code in question is in individual class files or is packaged into a Jar file. Alternately, and maybe better, you could update your question to reflect the true issue. – CryptoFool Jan 16 '22 at 01:03
  • @CryptoFool I faced the same problem and the same solution worked for me, but i didn't get why it happened; and how should I go ahead with writing code that's going to be used in production. – Bugs Buggy Mar 09 '23 at 07:42