加载log4j配置文件 Log4iConfigurer类

public class Log4iConfigurer {

    private static boolean INITIALIZED = false;

    public static void initLogger(){
if(!INITIALIZED&&!isConfigured()){
InputStream is =Log4iConfigurer.class.getClassLoader().getResourceAsStream("log4j.properties");
PropertyConfigurator.configure(is);
IOUtils.closeQuietly(is);
}
} private static boolean isConfigured() {
if(LogManager.getRootLogger().getAllAppenders().hasMoreElements()){
return true;
}else{
Enumeration<?> loggers =LogManager.getCurrentLoggers();
while(loggers.hasMoreElements()){
Logger logger= (Logger)loggers.nextElement();
if(logger.getAllAppenders().hasMoreElements()){
return true;
}
}
}
return false;
} }

读取配置文件类Util

public class Util {

    private static final Logger logger = LoggerFactory.getLogger(Util.class);

    /**mapping.properties file name*/
public static final Properties props = new Properties();
public static final String CONF_PROPERTIES_FILE= "mapping.properties";
public static final String CONF = "RUN_CONF"; static{
Log4iConfigurer.initLogger();
getProperties();
} public static String GetString(String key){
String value = null;
value = props.getProperty(key);
return value;
} //读取配置文件
private static File getConfProperties(){
String confHome = System.getProperty(CONF);
if(!StringUtils.isEmpty(confHome)){
logger.info("Use CONF="+confHome);
return getPropertiesFile(confHome);
} logger.warn("Conf property was not set ,will seek conf env variable"); String runHome = getRunHome();
if(StringUtils.isEmpty(runHome)){
throw new RuntimeException("didn't find project runpath,please set");
}
String path = runHome+File.separator+"conf";
return getPropertiesFile(path);
} public static void getProperties(){
File propFile = getConfProperties();
if(propFile == null||!propFile.exists()){
logger.info("fail to load properties");
throw new RuntimeException("fail to load properties");
}
FileInputStream fis = null;
try {
fis = new FileInputStream(propFile);
props.load(fis);
} catch (IOException e) {
throw new RuntimeException(e);
} finally {
IOUtils.closeQuietly(fis);
}
} private static File getPropertiesFile(String path){
if(path == null){
return null;
}
return new File(path,CONF_PROPERTIES_FILE);
} private static String getRunHome(){
String runHome = System.getProperty("runpath");
if(StringUtils.isEmpty(runHome)){
logger.warn("run home was not set");
}
return runHome;
} public static void main(String[] args) {
System.out.println(System.getenv("PATH"));
System.out.println(System.getProperty("conf"));
System.setProperty("run.home", "/home/dinpay/mappinghome");
System.out.println(System.getProperty("run.home"));
} }

打包导出

  

另外附上window和linux的启动脚本命令

startup.cmd

echo start elasticsearch-mapping
java -Drunpath=C:\Users\ll-t150\Desktop\esmap -Dlog4j.configuration=conf/log4j.properties -cp lib/* com.dinpay.bdp.rcp.service.Start
pause

startup.sh

echo start elasticsearch-mapping
java -Drunpath=/home/dinpay/esmap -Dlog4j.configuration=conf/log4j.properties -classpath .:lib/* com.dinpay.bdp.rcp.service.Start
echo "create elasticsearch mapping successfully!"

脚本命令加载外部配置文件夹conf的更多相关文章

  1. springboot加载外部配置文件

    网上搜集和整理如下(自己已验证过) 1. war包在tomcat中加载外部配置文件 war包运行在独立tomcat下时,如何加载war包外部配置application.properties,以达到每次 ...

  2. 19、属性赋值-@PropertySource加载外部配置文件

    19.属性赋值-@PropertySource加载外部配置文件 加载外部配置文件的注解 19.1 [xml] 在原先的xml 中需要 导入context:property-placeholder 声明 ...

  3. 【Spark】SparkStreaming-加载外部配置文件

    SparkStreaming-加载外部配置文件 spark加载配置文件_百度搜索 Spark加载外部配置文件 - CSDN博客 spark读取配置文件中的配置 - CSDN博客 spark加载prop ...

  4. SpringBoot系列——加载自定义配置文件

    前言 SpringBoot启动时默认加载bootstrap.properties或bootstrap.yml(这两个优先级最高).application.properties或application. ...

  5. 无阻塞加载外部js(动态脚本元素,XMLHttpRequest注入,LazyLoad)

    动态脚本元素即在js中去创建<script>标签加载外部js并执行,这样加载的好处是文件的下载和执行过程不会阻塞页面的其他进程.通过下面两个例子对比出效果 <!DOCTYPE htm ...

  6. 【Java Web开发学习】Spring加载外部properties配置文件

    [Java Web开发学习]Spring加载外部properties配置文件 转载:https://www.cnblogs.com/yangchongxing/p/9136505.html 1.声明属 ...

  7. Spark动态加载外部资源文件

    Spark动态加载外部资源文件 1.spark-submit --files 动态加载外部资源文件 之前做一个关于Spark的项目时,因项目中需要读取某个静态资源文件,然后在本地IDEA测试一切皆正常 ...

  8. selenium启动Chrome时,加载用户配置文件

    selenium启动Chrome时,加载用户配置文件   Selenium操作浏览器是不加载任何配置的,网上找了半天,关于Firefox加载配置的多点,Chrome资料很少,下面是关于加载Chrome ...

  9. UNITY_资源路径与加载外部文件

    UNITY_资源路径与加载外部文件 https://www.tuicool.com/articles/qMNnmm6https://blog.csdn.net/appppppen/article/de ...

随机推荐

  1. 菜鸟之路——机器学习之线性回归个人理解及Python实现

    这一节很简单,都是高中讲过的东西 简单线性回归:y=b0+b1x+ε.b1=(Σ(xi-x–)(yi-y–))/Σ(xi-x–)ˆ2       b0=y--b1x-    其中ε取 为均值为0的正态 ...

  2. nyoj 题目17 单调递增最长子序列

    单调递增最长子序列 时间限制:3000 ms  |  内存限制:65535 KB 难度:4   描述 求一个字符串的最长递增子序列的长度如:dabdbf最长递增子序列就是abdf,长度为4   输入 ...

  3. php获取客户端mac地址

    exec('/sbin/arp -a 2>&1', $array, $return_val);dump($array);$mac = '';foreach($array as $valu ...

  4. [luogu1707] 刷题比赛 [矩阵快速幂]

    题面: 传送门 思路: 一眼看上去是三个递推......好像还挺麻烦的 仔细观察一下,发现也就是一个线性递推,但是其中后面的常数项比较麻烦 观察一下,这里面有以下三个递推是比较麻烦的 第一个是$k^2 ...

  5. Java简明教程 12.多线程(multithreading)

    单线程和多线程 关于它们的区别,zhihu上有一个回答,我认为十分不错,如下: . 单进程单线程:一个人在一个桌子上吃菜. . 单进程多线程:多个人在同一个桌子上一起吃菜. . 多进程单线程:多个人每 ...

  6. 控制cxGrid 主从表的明细只展开一个

    procedure TForm.ADetailDataControllerCollapsing( ADataController: TcxCustomDataController; ARecordIn ...

  7. java修炼

    java程序员修炼之道——大牛告诉我们应该好好学习与修炼以下知识与技能   ———————————————————— 一:Java语言学习(对线程(thread),串行化,反射,网络编程,JNI技术, ...

  8. Use Razor for Email Template outside ASP.NET MVC

    原文发布时间为:2011-09-15 -- 来源于本人的百度文章 [由搬家工具导入] http://kazimanzurrashid.com/posts/use-razor-for-email-tem ...

  9. .NET抓取数据范例 抓取页面上所有的链接

    原文发布时间为:2009-11-15 -- 来源于本人的百度文章 [由搬家工具导入] .NET抓取数据范例 抓取页面上所有的链接 前台: <%@ Page Language="C#&q ...

  10. 又看了一次EM 算法,还有高斯混合模型,最大似然估计

    先列明材料: 高斯混合模型的推导计算(英文版): http://www.seanborman.com/publications/EM_algorithm.pdf 这位翻译写成中文版: http://w ...