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

posted on 2016-03-22 20:30  xuxu_dragon  阅读(2293)  评论(0编辑  收藏  举报