Clone wiki

metapossum-scanner / Home

´╗┐Metapossum Scanner

This is a handy little library to facilitate discovering resources on the classpath. While looking up a specific resource is easy, trying to exhaustively scan the classpath takes a bit more work if you want it to work correctly. This library does exactly that plus exports a ton of points to customize the search path, plus it has a generic interface to allow you to scan for whatever you want.

Typical Use Cases

Recursively search the classpath for classes that are annotated with the javax.persistence.Entity annotation (if for example you're tired of configuring your Hibernate session factory by listing all your classes individually):

Set<Class> entityClasses = new ClassesInPackageScanner()
	.findAnnotatedClasses("com.mypackage.datamodel", javax.persistence.Entity.class);

Find all classes that implement an interface:

Set<Class<? extends MyDiscoverableHelper>> implementingClasses = new ClassesInPackageScanner()
	.findImplementers("com.mypackage.service.impl", MyDiscoverableHelper.class);

Advanced Usage

There are a number of extension points to customize how and for what the scanner searches. Have a look at the API Docs to see just what's available!


This artifact is available in Maven Central. Add the following dependency to your project's pom.xml: