Old way of using Reflections doesnt find classes when run from commandline (java -jar myapp.jar
) anymore, despite being documented as still supported:
var reflections = new Reflections("com.package", Scanners.TypesAnnotated, Scanners.SubTypes);
Set<Class<?>> restBaseEnablingClasses = reflections.getTypesAnnotatedWith(MyAnnotation.class);
Still works in IDE (Intellij and Eclipse) though...
What could be the reason?
This is a known bug and is documented here
In my case workaround offered there kept giving me java.lang.SecurityException: sealing violation
because the BuiltinClassLoader
and ClassLoader used by reflections.io
library were loading jars twice - so I had to specify classloader when instantiating the Reflections class:
static Reflections reflections = new Reflections(
new ConfigurationBuilder()
.setClassLoaders(new ClassLoader[]{
ClassLoader.getPlatformClassLoader()
})
.setUrls(ClasspathHelper.forPackage("com.package")
)
);