多謝 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 讀取不到,這個有時間再探索下。。。