0

I prepared WAR archive and I deployed it on Wildfly 21. I want to find all classes annotated with javax.ws.rs.ApplicationPath annotation.

try (ScanResult scanResult = new ClassGraph().enableAllInfo().whitelistPackages( PACKAGE ).scan())
        {
            final ClassInfoList classesWithAnnotation =
                    scanResult.getClassesWithAnnotation( ApplicationPath.class.getName() );
        }

It finds two classes, one from my deployment and one from other deployment. I undeployed other deployment to make sure that one class is taken from it and I am sure, if only one deployment is deployed on Wildfly then it return only one class.

I do not understand why ClassGraph finds classes from other deployment. How to configure ClassGraph to scan only deployment which ClassGraph itself belongs? I guess that I have to configure class loader, but I do not know how to do it correctly.

Mariusz
  • 1,907
  • 3
  • 24
  • 39

1 Answers1

0

Unfortunately it seems that there is no any configuration options that could meet my requirements. Source code modification is needed.

There is JBossClassLoaderHandler#findClasspathOrder method. First org.jboss.modules.Module is retrieved from class loader. Next getCallerModuleLoader method is invoked and returns different class loader. Original class loader is an instance of org.jboss.modules.ModuleClassLoader class. Class loader retrieved by getCallerModuleLoader method is an instance of org.jboss.as.server.moduleservice.ServiceModuleLoader class. Next moduleMap method is invoked and returns map of modules. This map contains both my deployments. Next operations are executed for each map entry.

I also do not see possibility to add my own implementation of nonapi.io.github.classgraph.classloaderhandler.ClassLoaderHandler without source code modification because handlers are kept in unmodifiable final filed in ClassLoaderHandlerRegistry class.

Mariusz
  • 1,907
  • 3
  • 24
  • 39