L
Leonard Milcin Jr.
Hi!
Is it possible to find classes that are annotated with specific annotation?
I'm writing an application and I'd like to create very simple mechanism
that would allow me to use plugins. I would like to have a name for each
plugin and I would like to be able to find a class given this name (and
not the class name...). For example, I have an annotation like this:
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.TYPE)
public @interface Plugin {
String value();
}
and somewhere in the classpath there is a class TestTask:
@Plugin("testTask")
public class TestTask extends BaseTask {
static final Logger logger = Logger.getLogger(TestTask.class);
public void execute() throws TaskExecutionException {
logger.info("message from a plugin");
}
}
I'd like to be able to find class TestTask given the string testTask so
I could instantiate it and run whatever it does (in this case print
message to Log4J). How to do this?
Best Regards,
Leonard Milcin
Is it possible to find classes that are annotated with specific annotation?
I'm writing an application and I'd like to create very simple mechanism
that would allow me to use plugins. I would like to have a name for each
plugin and I would like to be able to find a class given this name (and
not the class name...). For example, I have an annotation like this:
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.TYPE)
public @interface Plugin {
String value();
}
and somewhere in the classpath there is a class TestTask:
@Plugin("testTask")
public class TestTask extends BaseTask {
static final Logger logger = Logger.getLogger(TestTask.class);
public void execute() throws TaskExecutionException {
logger.info("message from a plugin");
}
}
I'd like to be able to find class TestTask given the string testTask so
I could instantiate it and run whatever it does (in this case print
message to Log4J). How to do this?
Best Regards,
Leonard Milcin