0

我已经完成了我试图安装到 linux 机器上的 java 程序。不幸的是,我的程序没有看到属性文件并获取默认值。告诉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"));
4

1 回答 1

0

使用 maven 目录结构。将所有属性放在 src/main/resources 并加载它们

Properties prop = new Properties();
prop.load(PropertiesUtil.class.getClassLoader().getResourceAsStream("application.properties"));
于 2013-09-10T19:14:47.153 回答