In hadoop, when using configuration, the default configuration file, such as the core-default.xml, core-default.xml resource file, is automatically loaded first, the Code is as follows:
<span style="font-family:Microsoft YaHei;font-size:14px;">static{ //print deprecation warning if hadoop-site.xml is found in classpath ClassLoader cL = Thread.currentThread().getContextClassLoader(); if (cL == null) { cL = Configuration.class.getClassLoader(); } if(cL.getResource("hadoop-site.xml")!=null) { LOG.warn("DEPRECATED: hadoop-site.xml found in the classpath. " + "Usage of hadoop-site.xml is deprecated. Instead use core-site.xml, " + "mapred-site.xml and hdfs-site.xml to override properties of " + "core-default.xml, mapred-default.xml and hdfs-default.xml " + "respectively"); } addDefaultResource("core-default.xml"); addDefaultResource("core-site.xml"); }</span>
To build a good hadoop framework, many resource files written by yourself are bound to be used. hadoop supports XML better than properties files, and almost all configuration files in hadoop are written in XML. So how can I load my XML resource file to make it a global configuration?
Hadoop jar 'your jar package 'is followed by a-conf command to load its own resources. It depends on this command. OK, no nonsense. Go to the Code:
<Span style = "font-family: Microsoft yahei; font-size: 14px;"> package COM. ECOM. asillin. utils; import Org. apache. hadoop. conf. configuration;/*** created with intellij idea. * User: asilin * Date: 14-10-23 * Time: am * to change this template use file | Settings | file templates. */public class configurationutils {// static class Singleton {public static configurationutils instance = new configurationutils ();} private configurationutils () {} public static configurationutils getinstance () {return Singleton. instance;} // Add Resource public static configuration create () {configuration conn = new configuration (); addsources (conn); Return conn ;} // Add the Private Static configuration addsources (configuration conn) {Conn. addresource ("your xml file name,. XML, do not forget "); Return conn ;}</span>
Now the complete running command is: hadoop jar 'a. jar'-conf 'yourself. xml'
Hadoop loads self-owned resource files