程序运行,
有时候需要获取jar包内内容, 例如版本更新信息,新增文本提示等
有时候需要获取jar包外内容, 例如每个系统运行的环境, 系统名称等
当前用的是spring clud框架
获取到jar包内配置文件
String fileName = "文件名.xml";
InputStream is = this.getClass().getResourceAsStream("/"+fileName); //通过java getclass 获取到jar包内文件, 获取到输入流
private static Map verMap = new HashMap<>();
if (document == null)
return;
List> tables = document.selectNodes("UrlList"); //通过document 的方法, 解析xml
if (tables != null && tables.size() > 0) {
for (Object obj : tables) {
Element urlList = (Element) obj;
for (Object urlObj : urlList.selectNodes("url")) {
Element urlElement = (Element) urlObj;
String verid = urlElement.attributeValue("verid");
String vernum = urlElement.attributeValue("vernum");
String vertime = urlElement.attributeValue("vertime");
String vertext = urlElement.getText();
if (!verMap.containsKey(verid)){
ObjectNode objectNode = Convert.newObject();
objectNode.put("verid", verid);
objectNode.put("vernum", vernum);
objectNode.put("vertime", vertime);
objectNode.put("vertext", vertext);
verMap.put(verid, objectNode);
}
}
}
}
2、
1、
通过ConfigUtil.getApplicationPath()获取到项目运行绝对地市
File.separator 斜线, 文件夹符号
String configPath = "file:"+ConfigUtil.getApplicationPath()+File.separator+"conf"+File.separator+"applicationContext.xml";