-
1. Re: Wildfly and Reflections library
fharms Mar 15, 2015 12:14 PM (in response to avishaybennatan)Not entirely sure what you are trying to achieve, but it sound like a class loader issue. Depending on which archive type you are using, you might have to give access to the classes you want to scan
Look into jboss-deployment-structure.xml Class Loading in WildFly - WildFly 8 - Project Documentation Editor
/Flemming
-
2. Re: Wildfly and Reflections library
pmm Mar 16, 2015 9:26 AM (in response to avishaybennatan)Avishay Ben Natan wrote:
Hi
I am trying to scan classes with Reflections library,
Don't
-
3. Re: Wildfly and Reflections library
robert.baum Oct 13, 2016 10:24 AM (in response to avishaybennatan)Might be a bit late, but I was having similar issues when running on Wildfly and managed to get it working. I fixed it by instantiating the Reflections object with a servletContext.
To get a servletContext, the class you are using this in needs to implement ServletContextAware and Override setServletContext. To ensure the Reflections object gets set up correctly with the servletContext, I also implemented InitializingBean and instantiated it in afterPropertiesSet
if (servletContext.getResourcePaths("/WEB-INF/lib") != null) { //This folder doesn't exist if running in IDE for me.
urlsToScan.addAll(ClasspathHelper.forWebInfLib(servletContext));
urlsToScan.add(ClasspathHelper.forWebInfClasses(servletContext));
} else {
urlsToScan.addAll(ClasspathHelper.forJavaClassPath());
}
final Reflections eligibleClasses = new Reflections(new ConfigurationBuilder().setScanners(new SubTypesScanner(false)).setUrls(urlsToScan)
.filterInputsBy(new FilterBuilder().include(FilterBuilder.prefix(basePackage))));
//Use it as normal . . .
Hope someone finds this useful.
-
4. Re: Wildfly and Reflections library
kot.filemon Nov 16, 2016 1:27 PM (in response to pmm)> Don't
could You write why not?
is it connected with the library or just generaly with java reflection API?
any recommended way to use reflection in Wildfly?
-
5. Re: Wildfly and Reflections library
russ396 Jan 11, 2017 10:58 AM (in response to avishaybennatan)Reflections reflections = new Reflections("com"); This worked for me.
-
6. Re: Wildfly and Reflections library
pmm Mar 28, 2017 1:50 AM (in response to kot.filemon)Marcin M wrote:
> Don't
could You write why not?
You can not introspect into a class loader, this is not supported by the class loader API. Only the container can introspect into the class loader as it controls the class loader. The only way you can introspect into a class loader is making a whole lot of assumptions that are not guaranteed and will fail eventually.
If you insist I would recommend introspecting at build time and writing that information into a file that you include in your deployment and then read that file at runtime.