调用jar程序,读取与jar同级的配置文件。

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

原文地址:https://www.cnblogs.com/xuxu-dragon/p/5308327.html