I want to write a small SE application to run OS-specific commands. These commands are supplied to the main application as "plugins", in order to be able to add new command implementation at runtime. This is a mandatory request: that no redeploy of the main application be required to execute new plugins.
So, I went about trying to setup something using CDI:
// On a common dependency
@Qualifier
@Retention(RUNTIME)
@Target({TYPE, METHOD, FIELD, PARAMETER})
public @interface Plugin {
String value();
}
public interface Pluggable {
void execute(PluginContext context);
}
A plugin implementation would be something like this (in a separate jar):
@Plugin("greeting")
public class GreetingPlugin implements Pluggable {
public void execute(PluginContext context) {
String greet = context.get("hello.world");
System.out.println(String.format("Hello, %s", greet));
}
}
And that works fine, when loaded using the following injection point, plus a select() call:
@Inject @Any Instance<Pluggable> plugin;
However, I wonder what's the best approach to add the ability to add classes at runtime, so that the event of adding a new file to the "plugins" directory automatically registers it on the ClassLoader and the Weld container.
Any suggestions? Pitfalls I've not yet considered? My experience with CDI is rather limited, and perhaps it might not even be a suitable choice for this problem.
Disclaimer OSGI is ruled out, due to company licensing policy. Can't help on that front.