脚本命令加载外部配置文件夹conf
加载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的更多相关文章
- springboot加载外部配置文件
网上搜集和整理如下(自己已验证过) 1. war包在tomcat中加载外部配置文件 war包运行在独立tomcat下时,如何加载war包外部配置application.properties,以达到每次 ...
- 19、属性赋值-@PropertySource加载外部配置文件
19.属性赋值-@PropertySource加载外部配置文件 加载外部配置文件的注解 19.1 [xml] 在原先的xml 中需要 导入context:property-placeholder 声明 ...
- 【Spark】SparkStreaming-加载外部配置文件
SparkStreaming-加载外部配置文件 spark加载配置文件_百度搜索 Spark加载外部配置文件 - CSDN博客 spark读取配置文件中的配置 - CSDN博客 spark加载prop ...
- SpringBoot系列——加载自定义配置文件
前言 SpringBoot启动时默认加载bootstrap.properties或bootstrap.yml(这两个优先级最高).application.properties或application. ...
- 无阻塞加载外部js(动态脚本元素,XMLHttpRequest注入,LazyLoad)
动态脚本元素即在js中去创建<script>标签加载外部js并执行,这样加载的好处是文件的下载和执行过程不会阻塞页面的其他进程.通过下面两个例子对比出效果 <!DOCTYPE htm ...
- 【Java Web开发学习】Spring加载外部properties配置文件
[Java Web开发学习]Spring加载外部properties配置文件 转载:https://www.cnblogs.com/yangchongxing/p/9136505.html 1.声明属 ...
- Spark动态加载外部资源文件
Spark动态加载外部资源文件 1.spark-submit --files 动态加载外部资源文件 之前做一个关于Spark的项目时,因项目中需要读取某个静态资源文件,然后在本地IDEA测试一切皆正常 ...
- selenium启动Chrome时,加载用户配置文件
selenium启动Chrome时,加载用户配置文件 Selenium操作浏览器是不加载任何配置的,网上找了半天,关于Firefox加载配置的多点,Chrome资料很少,下面是关于加载Chrome ...
- UNITY_资源路径与加载外部文件
UNITY_资源路径与加载外部文件 https://www.tuicool.com/articles/qMNnmm6https://blog.csdn.net/appppppen/article/de ...
随机推荐
- RESTful-rest_framework认证组件、权限组件、频率组件-第五篇
认证组件.权限组件.频率组件总结: 认证组件格式: 1 写一个认证类 from rest_framework.authentication import BaseAuthentication cla ...
- python中 in, any 和 all用法
in if x == 1 or y == 1 or z == 1: print('passed') if 1 in (x, y, z): print('passed') any if x or y o ...
- Android之操作相册
获取手机中的图片的绝对路径并且区分出每个文件夹下的路径: 存放图片绝对路径的文件夹的名字和存放绝对路径的List 实体类如下: import java.util.ArrayList; import j ...
- ios动画效果集锦(持续更新)
1.树叶滚动进度:http://www.jianshu.com/p/800496caa055 2.列表滚动动画和滚动视差效果http://www.jianshu.com/p/42e1eb59a1af ...
- BZOJ3561 DZY Loves Math VI 【莫比乌斯反演】
题目 给定正整数n,m.求 输入格式 一行两个整数n,m. 输出格式 一个整数,为答案模1000000007后的值. 输入样例 5 4 输出样例 424 提示 数据规模: 1<=n,m<= ...
- 1.docker学习
Docker —— 从入门到实践 http://udn.yyuap.com/doc/docker_practice/introduction/index.html 非常详细的Docker学习教程 ht ...
- css 两列自适应布局的4种思路
前面的话 前面已经介绍过css 两列布局中单列定宽单列自适应布局的6种思路的两列布局,而两列自适应布局是指一列由内容撑开,另一列撑满剩余宽度的布局方式.本文将从float.table.flex和gri ...
- 沼泽鳄鱼(bzoj 1898)
Description 潘塔纳尔沼泽地号称世界上最大的一块湿地,它地位于巴西中部马托格罗索州的南部地区.每当雨季来临,这里碧波荡漾.生机盎然,引来不少游客.为了让游玩更有情趣,人们在池塘的中央建设了几 ...
- L-Gap Substrings(uva 10829)
题意:有一种形如uvu形式的字符串,其中u是非空字符串,且V的长度正好为L,那么称这个字符串为L-Gap字符串 给出一个字符串S,以及一个正整数L,问S中有多少个L-Gap子串. /* 这道题用到一个 ...
- DataGrid关键字变色
原文发布时间为:2009-05-01 -- 来源于本人的百度文章 [由搬家工具导入] private void DataGrid1_ItemDataBound(object sender, ...