0

I want to do the following using Google Reflections:

  1. Scan only WEB-INF/lib/Patrac-ejb.jar

  2. Scan only the package com.patrac and all of its sub-packages.

  3. Scan for only type- and method annotations.

The following configuration seems to work fine but I don't have any experience with Google Reflections.

Reflections reflections = new Reflections(
    new ConfigurationBuilder()
        .filterInputsBy(new FilterBuilder().include("Patrac-ejb.jar").include(FilterBuilder.prefix("com.patrac")))
        .setScanners(new MethodAnnotationsScanner(), new TypeAnnotationsScanner())
        .setUrls(ClasspathHelper.forWebInfLib(servletContext))
);

It appears to be working. I want to make sure it's not scanning all the other JARs in WEB-INF/lib. Is there an easy way to discover what JARs are being matched by the filter inputs in the configuration? Any advice about my approach would be much appreciated.

Patrick Garner
  • 3,201
  • 6
  • 39
  • 58

1 Answers1

0

The following worked:

   //   Get the URL for Patrac-ejb.jar:
   Set<URL> urls = ClasspathHelper.forWebInfLib(webUtil.getServletContext());
   URL patracJarUrl = null;
   for(URL url : urls)
   {
       if(url.getFile().endsWith("Patrac-ejb.jar"))
       {
           patracJarUrl = url;
           break;
       }
   }
   if(null == patracJarUrl)
   {
       throw new IllegalStateException("Patrac-ejb.jar not found.");
   }

   //   Add the Patrac-ejb.jar URL to the configuration.
   Configuration configuration = new ConfigurationBuilder()
       .filterInputsBy(new FilterBuilder()
                       .include(FilterBuilder.prefix("com.patrac")))
       .setScanners(new MethodAnnotationsScanner(), new TypeAnnotationsScanner())
       .setUrls(patracJarUrl);
Patrick Garner
  • 3,201
  • 6
  • 39
  • 58