Hadoop loads self-owned resource files

Source: Internet
Author: User
Tags deprecated

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.