Hi,
I just found out that it's not possible to invoke main() methods of
plugins through the bin/nutch script. Sometimes it's useful for testing
and debugging - I can do it from within Eclipse, because I have all
plugins on the classpath, but from the command-line it's not possible -
in the code they are accessed through PluginRepository. So I added this:
public static void main(String[] args) throws Exception {
NutchConf conf = new NutchConf();
PluginRepository repo = new PluginRepository(conf);
// args[0] - plugin ID
PluginDescriptor d = repo.getPluginDescriptor(args[0]);
if (d == null) {
System.err.println("Plugin '" + args[0] + "' not present or
inactive.");
return;
}
ClassLoader cl = d.getClassLoader();
// args[1] - class name
Class clazz = Class.forName(args[1], true, cl);
Method m = clazz.getMethod("main", new Class[]{args.getClass()});
String[] subargs = new String[args.length - 2];
System.arraycopy(args, 2, subargs, 0, subargs.length);
m.invoke(null, new Object[]{subargs});
}
It works rather nicely. If other people find it useful, I can add this
to PluginRepository.
--
Best regards,
Andrzej Bialecki <><
___. ___ ___ ___ _ _ __________________________________
[__ || __|__/|__||\/| Information Retrieval, Semantic Web
___|||__|| \| || | Embedded Unix, System Integration
http://www.sigram.com Contact: info at sigram dot com