我已经完成了java程序,我正在尝试安装到linux机器上。不幸的是,我的程序没有看到属性文件并获取默认值。告诉java放置属性文件的方法是什么?
Program is placed in:
/opt/myProg
Properties are placed in:
/opt/myProg/config.ini
external jar:
/opt/myProg/lib
classes in packeges:
/opt/myProg/Prog
Command I'm trying to run my program:
java -cp /opt/myProg/lib/log4j.jar:/opt/myProg/Prog:/opt/myProg/. startpkg.runme
此命令也没有帮助:
java -cp /opt/myProg/lib/log4j.jar:/opt/myProg/Prog:/opt/myProg/. startpkg.runme -Dconfig.ini=/opt/myProg/config.ini
尝试加载道具的代码如下所示:
p.load(new FileInputStream("config.ini"));
答案 0 :(得分:0)
使用maven目录结构。将所有属性放在src / main / resources中并使用
加载它们Properties prop = new Properties();
prop.load(PropertiesUtil.class.getClassLoader().getResourceAsStream("application.properties"));