Hadoop loads self-owned xml resource files

Source: Internet
Author: User

Hadoop loads self-owned xml resource files

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:

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 ");
}

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:

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
Private static class Singleton {
Public static ConfigurationUtils instance = new ConfigurationUtils ();
}

Private ConfigurationUtils (){}

Public static ConfigurationUtils getInstance (){
Return Singleton. instance;
}

// Add resources
Public static Configuration create (){
Configuration conn = new Configuration ();
AddSources (conn );
Return conn;
}

// Add resources after default resource-conf
Private static Configuration addSources (Configuration conn ){
Conn. addResource ("your xml file name, with. xml, do not forget ");
Return conn;
}
}

Now the complete running command is: hadoop jar 'a. jar'-conf 'yourself. xml'

Build a Hadoop environment on Ubuntu 13.04

Cluster configuration for Ubuntu 12.10 + Hadoop 1.2.1

Build a Hadoop environment on Ubuntu (standalone mode + pseudo Distribution Mode)

Configuration of Hadoop environment in Ubuntu

Detailed tutorial on creating a Hadoop environment for standalone Edition

Build a Hadoop environment (using virtual machines to build two Ubuntu systems in a Winodws environment)

 

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.