Java runtime metadata analysis

License: WTFPL

Language: Java

Java runtime metadata analysis, in the spirit of Scannotations

Reflections scans your classpath, indexes the metadata, allows you to query it on runtime and may save and collect that information for many modules within your project.

Using Reflections you can query your metadata such as:

  • get all subtypes of some type
  • get all types/members annotated with some annotation
  • get all resources matching a regular expression
  • get all methods with specific signature including parameters, parameter annotations and return type

Build Status


Add Reflections to your project. for maven projects just add this dependency:


A typical use of Reflections would be:

Reflections reflections = new Reflections("my.project");

Set<Class<? extends SomeType>> subTypes = reflections.getSubTypesOf(SomeType.class);

Set<Class<?>> annotated = reflections.getTypesAnnotatedWith(SomeAnnotation.class);


Basically, to use Reflections first instantiate it with urls and scanners

//scan urls that contain 'my.package', include inputs starting with 'my.package', use the default scanners
Reflections reflections = new Reflections("my.package");

//or using ConfigurationBuilder
new Reflections(new ConfigurationBuilder()
     .setScanners(new SubTypesScanner(), 
                  new TypeAnnotationsScanner().filterResultsBy(optionalFilter), ...),
     .filterInputsBy(new FilterBuilder().includePackage("my.project.prefix"))

Then use the convenient query methods: (depending on the scanners configured)

Set<Class<? extends Module>> modules = 
Set<Class<?>> singletons = 
Set<String> properties = 
Set<Method> resources =
Set<Constructor> injectables = 
Set<Field> ids = 
Set<Method> someMethods =
    reflections.getMethodsMatchParams(long.class, int.class);
Set<Method> voidMethods =
Set<Method> pathParamMethods =
List<String> parameterNames = 
Set<Member> usages = 
  • If no scanners are configured, the default will be used - SubTypesScanner and TypeAnnotationsScanner.
  • Classloader can also be configured, which will be used for resolving runtime classes from names.
  • Reflections expands super types by default. This solves some problems with transitive urls are not scanned.

Checkout the javadoc for more info.

Also, browse the tests directory to see some more examples.


ReflectionsUtils contains some convenient Java reflection helper methods for getting types/constructors/methods/fields/annotations matching some predicates, generally in the form of *getAllXXX(type, withYYY)

for example:

import static org.reflections.ReflectionUtils.*;

Set<Method> getters = getAllMethods(someClass,
  withModifier(Modifier.PUBLIC), withPrefix("get"), withParametersCount(0));

Set<Method> listMethodsFromCollectionToBoolean = 
    withParametersAssignableTo(Collection.class), withReturnType(boolean.class));

Set<Fields> fields = getAllFields(SomeClass.class, withAnnotation(annotation), withTypeAssignableTo(type));

See more in the ReflectionUtils javadoc

Integrating into your build lifecycle

Although scanning can be easily done on bootstrap time of your application - and shouldn't take long, it is sometime a good idea to integrate Reflections into your build lifecyle. With simple Maven/Gradle/SBT/whatever configuration you can save all scanned metadata into xml/json files just after compile time. Later on, when your project is bootstrapping you can let Reflections collect all those resources and re-create that metadata for you, making it available at runtime without re-scanning the classpath - thus reducing the bootstrapping time.

For Maven, see example using gmavenplus in the reflections-maven repository

Other use cases

See the UseCases wiki page


Pull requests are welcomed!!

The license is WTFPL, just do what the fuck you want to.

This library is published as an act of giving and generosity, from developers to developers.

Please feel free to use it, and to contribute to the developers community in the same manner. Dāna Donate

Welcome to join the conversation and share your thoughts on the license issue.


Project Statistics

Sourcerank 17
Repository Size 370 KB
Stars 2,844
Forks 497
Watchers 194
Open issues 102
Dependencies 9
Contributors 20
Tags 3
Last updated
Last pushed

Top Contributors See all

ronmamo Stephen Colebourne ronm-logz Johannes Mockenhaupt Florent Ramière Stephan Schroevers Pierre T. Wolf480pl Michael Schnell Arne Georg Gisnås Gleditsch Knute G. Axelson nigelsim Yuxing Li actong Jim Tang Mark Kolich Geoffrey De Smet Sergej Zagursky Sean Owen Kenny MacLeod

Packages Referencing this Repo

Reflections - a Java runtime metadata analysis
Latest release 0.9.11 - Updated - 2.84K stars
Reflections Maven plugin
Latest release 0.9.9-RC2 - Updated - 2.84K stars

Recent Tags See all

0.9.11 March 09, 2017
21959e6e January 13, 2017
0.9.11-SNAPSHOT January 13, 2017

Interesting Forks See all

Java8 runtime metadata analysis reflections without guava
Java - WTFPL - Last pushed - 8 stars - 3 forks
**This is a fork of reflections library to unblock our development with the newest version of thi...
Java - WTFPL - Last pushed - 1 stars
Java - Updated - 1 stars - 1 forks
This repository is no longer maintained - Last pushed
Java - Updated - 1 stars

Something wrong with this page? Make a suggestion

Last synced: 2017-03-28 02:00:11 UTC

Login to resync this repository