您的位置:首页 > 编程语言

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

2012-01-06 11:32 513 查看
昨天在一个项目中,需要额外读取一个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 读取不到,这个有时间再探索下。。。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: