在代码中读取MAXIMO的安装路径, 同时读取properties文件

昨天在一个项目中,需要额外读取一个properties文件,properties文件存放在maximo/properties文件夹下。首先这就要读取到maximo的安装路径,当然这也是最关键的一步。

多谢 Fedora Maximo(438658902) 提供的hello.class.getProtectionDomain().getCodeSource().getLocation().getFile()方法。呵呵,现在把测试代码贴出来:

String locTemp = CuMRActionAPPR2YG.class.getProtectionDomain().getCodeSource().getLocation().getFile();
String maximoAddress = locTemp.substring(1, locTemp.lastIndexOf("maximo"));
Properties prop = new Properties();
InputStream in = null;
try {
	in = new BufferedInputStream(new FileInputStream(maximoAddress+"properties/ygjk.properties"));
	
	prop.load(in); 
    fmisAddress = prop.getProperty("fmis.address.ip").trim();
    System.out.println("fmisAddress:>>>"+fmisAddress);
	
} catch (FileNotFoundException e1) {
	e1.printStackTrace();
	throw new MXApplicationException("提示 #", "配置文件不存在,请与管理员联系。");
} catch (IOException e) {
	e.printStackTrace();
	throw new MXApplicationException("提示 #", "读取配置文件错误,,请与管理员联系。");
} finally {
	if(in != null){
		try {
			in.close();
		} catch (IOException e) {
			e.printStackTrace();
		}
	}
}

在探索的过程中发现了maximo自带一个读取配置文件的方法:

String tempPro = MXServer.getMXServer().getProperty("fmis.address.ip");
System.out.println(">>>>>>>>>"+tempPro);
但是貌似这个方法只能读取maximo自带的那个maximo.properties中的配置。自己加上去的key-value 读取不到,这个有时间再探索下。。。


  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值