For example if I have annotation @MyOwnAnnotation
and have these classes in my classpath, so that I could scan classpath possibly with some kind of filter (example. scan only packages starting with my.own.app.*
) and get list of all classes with annotation @MyOwnAnnotation
? I'm using guice as injection framework and I don't use Spring.
Yes, check out the Scannotation library.
Also, see the following blog post that documents use of Scannotation.
Basic example:
URL[] urls = ClasspathUrlFinder.findClassPaths(); // scan java.class.path
AnnotationDB db = new AnnotationDB();
db.scanArchives(urls);
Set<String> entityClasses =
db.getAnnotationIndex().get(MyOwnAnnotation.class.getName());
Your annotations will need to have 'runtime' retention so that they are available in the .class
file at runtime.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With