3

I need to create a list of subclasses for a particular interface during maven build process and then use that at runtime to load those classes. I have added reflections-maven (from google code reflections) in my webapp pom but during maven build, its only including the classes from the web application and not the classes inside the packaged jars that are there in web-inf/lib folder of that application. Below is the straight forward configuration I have used. I looked at the plugin source code and it seems it scans the following: getProject().getBuild().getOutputDirectory().

Is there anyways I can configure the plugin to scan the dependent jar files of the project?

<plugin> <groupId>org.reflections</groupId> <artifactId>reflections-maven</artifactId> <version>0.9.9-RC1</version> <executions> <execution> <goals> <goal>reflections</goal> </goals> <phase>process-classes</phase> </execution> </executions> </plugin> 

1 Answer 1

7

You can easily run Reflections with any configuration you like, using, for example, gmaven-plugin:

<plugin> <groupId>org.codehaus.gmaven</groupId> <artifactId>gmaven-plugin</artifactId> <version>1.3</version> <dependencies> <dependency> <groupId>org.reflections</groupId> <artifactId>reflections</artifactId> <version>0.9.9-RC1</version> </dependency> </dependencies> <executions> <execution> <phase>generate-resources</phase> <goals> <goal>execute</goal> </goals> <configuration> <source> new org.reflections.Reflections("f.q.n") .save("${project.build.outputDirectory}/META-INF/reflections/${project.artifactId}-reflections.xml") </source> </configuration> </execution> </executions> </plugin> 

So all you need to do is to use the right configuration, maybe in your specific case:

def urls = org.reflections.util.ClasspathHelper.forWebInfLib() new org.reflections.Reflections(urls) .save("${project.build.outputDirectory}/META-INF/reflections/${project.artifactId}-reflections.xml") 
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.