小结:
(1)在nutch中,一般通过ToolRunner来运行hadoop job,此方法可以方便的通过ToolRunner.run(Configuration conf,Tool tool,String[] args)来加载配置文件。
(2)conf参数会通过NutchConfiguration.creat()方法创建,此方法先加载hadoop的core-default.xml与core-site.xml,然后再加载nutch-default.xml与nutch-site.xml。
public static Configuration create() { Configuration conf = new Configuration(); setUUID(conf); addNutchResources(conf); return conf; }
private static Configuration addNutchResources(Configuration conf) { conf.addResource("nutch-default.xml"); conf.addResource("nutch-site.xml"); return conf; }
/** Create a {@link Configuration} from supplied properties. * @param addNutchResources if true, then first <code>nutch-default.xml</code>, * and then <code>nutch-site.xml</code> will be loaded prior to applying the * properties. Otherwise these resources won't be used. * @param nutchProperties a set of properties to define (or override) */ public static Configuration create(boolean addNutchResources, Properties nutchProperties) { Configuration conf = new Configuration(); setUUID(conf); if (addNutchResources) { addNutchResources(conf); } for (Entry<Object, Object> e : nutchProperties.entrySet()) { conf.set(e.getKey().toString(), e.getValue().toString()); } return conf; }
private NutchConfiguration() {} // singleton
public static void main(String[] args) throws Exception { final int res = ToolRunner.run(NutchConfiguration.create(), new SolrIndexerJob(), args); System.exit(res); }