脚本命令加载外部配置文件夹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 ...
随机推荐
- 精通CSS高级Web标准解决方案(5、对列表应用样式和创建导航条)
5.1基本样式列表 去掉列表的默认样式: ul{ margin:; padding:; list-style-type:none; } 添加定制的符号,在列表左边添加填充,为符号留出空间,然后将符号图 ...
- bzoj4030【HEOI2015】小L的白日梦
题意:http://www.lydsy.com/JudgeOnline/problem.php?id=4030 sol :orz Yousiki http://www.cnblogs.com/you ...
- create-react-app 配置支持sass并集成autoprefixer插件
create-react-app的webpack配置在node_modules当中的react-scripts的config文件夹当中,其中webpack.config.dev.js是开发环境的配置, ...
- LOJ#2083. 「NOI2016」优秀的拆分
$n \leq 30000$的字符串,问其所有子串的所有AABB形式的拆分有多少种.$t \leq 10$组询问. $n^3$过80,$n^2$过95,鬼去写正解.. $n^2$:先枚举一次算每个位置 ...
- SQL:某个字段重复的时候只查询出最后插入的那条
原文发布时间为:2009-04-11 -- 来源于本人的百度文章 [由搬家工具导入] 数据库com中有下列数据 id,userid,tupian,time 1 3 3 2006.3.5 2 4 4 2 ...
- User Experience Collection
about a data driven system front end: 1. about succeeded requests: they do not want to see alerts ab ...
- 关于mysql编码问题
1 查看MySQL编码 SHOW VARIABLES LIKE 'char%';
- hdu 2732 Leapin' Lizards 最大流 拆点 建图
题目链接 题意 给定一张网格,格子中有些地方有柱子,有些柱子上面有蜥蜴. 每个柱子只能承受有限只蜥蜴从上面经过.每只蜥蜴每次能走到相距曼哈顿距离\(\leq k\)的格子中去. 问有多少只蜥蜴能走出网 ...
- Android Bluetooth抓包
1. 前提 这里介绍一种在Android上捕获蓝牙数据包的方法 首先你要有一部Android手机:然后你的Android系统版本要在4.4及以上 我没有做过Android开发,不清楚开发者们是如何抓蓝 ...
- js 验证数字的正则表达式集
<script type="text/javascript"> function validate(){ var reg = new RegExp( ...