Find annotated classes on runtime

Hello,is there a way to find all classes, that are annotated with a given annotation on runtime of an application? I am using Java 1.6. If I got it right the JSR 269 Pluggable Annotation Processing API can only be used with javac.Greetings and thanks in advance,Max
[293 byte] By [Boerecka] at [2007-11-26 20:52:55]
# 1

Yep, Pluggable Annotation Processing API is a build time API, implemented by javac, and also the eclipse compiler.

You would need to use the java.lang.reflect API to do what you want.

The difficulty is that it does not directly give you access to all classes loaded into the JVM.

Use the java.lang.instrument mechanisms to instrument your app, See http://java.sun.com/javase/6/docs/api/java/lang/instrument/Instrumentation.html

and that interface can tell you all the loaded classes. Then just check them all.

have fun.

brucechapmana at 2007-7-10 2:18:44 > top of Java-index,Core,Core APIs...
# 2

Thank you for that idea.

Unfortunately this solution needs VM implementation specific classes, when starting on runtime. I hope there will be a standardised way to do this in a future version of the jdk.

Since the classes I need to scan are all in one directory, I search all .class files in that directory and check the corresponding class-objects in my current implementation. It is no neat solution, but it works.

Boerecka at 2007-7-10 2:18:45 > top of Java-index,Core,Core APIs...