System.getProperty("user.dir") + "\\Mysettings.properties";//该方法在Alimonitor里取不到绝对路径
改成如下方法便可解决此问题:
/**
* 得到jar配置文件路径
* */
String GetPropertyFilePath() throws IOException
{
String jarWholePath = this.getClass().getProtectionDomain().getCodeSource().getLocation().getFile();
jarWholePath = java.net.URLDecoder.decode(jarWholePath, "UTF-8");
String jarPath = new File(jarWholePath).getParentFile().getAbsolutePath()+"/"+propertyFile;
return jarPath;
}
Alimonitor中采集脚本:
/usr/local/java/jdk1.7.0/bin/java -jar /home/admin/aliMinitor/AutolrNagiosMonitor/AutolrNagiosMonitor-0.0.1-SNAPSHOT.jar flowData
本文介绍了一种在Alimonitor中获取正确配置文件路径的方法,解决了System.getProperty无法获取绝对路径的问题。通过获取jar文件的完整路径并进行解码,最终形成正确的配置文件路径。
990

被折叠的 条评论
为什么被折叠?



