调用jar程序,读取与jar同级的配置文件。
2016-03-22 20:30
134 查看
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
改成如下方法便可解决此问题:
/**
* 得到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
相关文章推荐
- POJ 2392 Space Elevator
- 结对项目— 词频统计(语言C++)
- 【字符串水题】HDU2617Happy 2009
- 解决小米蓝牙耳机无法被检测、无法连接的问题
- 求逆元偷懒方法
- 瑞士轮
- 永远不要打探别人工资
- Alcatraz
- POJ 1017 Packets (贪心)
- 第四周项目5.4—编制递归函数返回第n个Fibnacci数
- leetcode118 & 119. [Array]Pascal's Triangle
- 代码复审
- 链表的操作
- HDU_2604Queuing
- Android 中MD5算法生成字符串
- Android:控件Spinner实现下拉列表
- C++ static静态成员变量和静态成员函数
- lintcode: Construct Binary Tree from Preorder and Inorder Traversal
- 二元谓词的重载2
- 从linux启动到rootfs的挂载分析