在代碼中讀取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 讀取不到,這個有時間再探索下。。。


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章