脚本命令加载外部配置文件夹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 ...
随机推荐
- spaCy 并行分词
spaCy 并行分词 在使用spacy的时候,感觉比nltk慢了许多,一直在寻找并行化的方案,好在找到了,下面给出spaCy并行化的分词方法使用示例: import spacy nlp = spacy ...
- asp.net允许跨域访问
C# ASP.NET MVC 配置允许跨域访问 在web.config文件中的 system.webServer 节点下 增加如下配置 <httpProtocol> <customH ...
- BZOJ 2818: Gcd(欧拉函数)
GCDDescription 给定整数N,求1<=x,y<=N且Gcd(x,y)为素数的数对(x,y)有多少对. Input 一个整数N Output 如题 Sample Input 4 ...
- 【距离GDOI:141天】 滚入数位DP的坑
作为博客园的第一篇...我都不知道要写什么了 ... 其实今天很没状态,就当吐槽吧... 嗯,被黄神带去写treap+可持久化线段树,然后在可持久化的删除上面跪了两天,真的是一跪不起.我已经连续多久没 ...
- 洛谷P1822 魔法指纹 【分块打表】
题目 对于任意一个至少两位的正整数n,按如下方式定义magic(n):将n按十进制顺序写下来,依次对相邻两个数写下差的绝对值.这样,得到了一个新数,去掉前导0,则定义为magic(n).若n为一位数, ...
- 旅行商(sale)
旅行商(sale) 题目描述 camp国有n座城市,由1,2,-,n编号.城市由n–1条双向道路相连.任意两个城市之间存在唯一的道路连通.有m个旅行商,第i个旅行商会从城市ai旅行到城市bi,贩卖ci ...
- id_rsa id_rsa.pub
id_rsa 私钥 id_rsa.pub 公钥 https://blog.csdn.net/qq_36663951/article/details/78749217 https://blog.cs ...
- AngularJS实现TodoMVC
一个小的to do list,界面如下 首先安装angular js,出现了无非安装到桌面的问题,安装到D盘了 npm install angular 文件结构: index.html: <!d ...
- 【16】vuex2.0 之 getter
有的组件中获取到 store 中的state, 需要对进行加工才能使用,computed 属性中就需要写操作函数,如果有多个组件中都需要进行这个操作,那么在各个组件中都写相同的函数,那就非常麻烦,这 ...
- html5 的 webScoket 和 C# 建立Socket连接
最近使用的web项目中,需要服务器直接触发前端显示效果. 所以研究了一下websocket: 名词解释: WebSocketWebSocket协议是一种双向通信协议,它建立在TCP之上,同http一样 ...