标签:style io os ar 使用 java sp 文件 on
在hadoop中,使用configuration的时候,首先自动加载了默认的配置文件,比如core-default.xml、core-default.xml资源文件,代码如下:
<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>
hadoop jar ‘你的jar包’ 之后跟随着一个-conf的命令,加载自有资源,靠的就是这个命令,ok,不废话了,上代码:
<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: 上午10:17 * To change this template use File | Settings | File Templates. */ public class ConfigurationUtils { //静态类单例 private static class Singleton{ public static ConfigurationUtils instance = new ConfigurationUtils(); } private ConfigurationUtils(){} public static ConfigurationUtils getInstance(){ return Singleton.instance; } //添加资源 public static Configuration create(){ Configuration conn = new Configuration(); addSources(conn); return conn; } //添加默认资源 -conf 之后的资源 private static Configuration addSources(Configuration conn){ conn.addResource("你的xml文件名称,带有.xml,不要忘记"); return conn; } } </span>ok 现在完整的运行命令就是: hadoop jar ‘a.jar’ -conf ‘yourself.xml’
标签:style io os ar 使用 java sp 文件 on
原文地址:http://blog.csdn.net/qingmu0803/article/details/40395385