0

我有以下属性文件

文件位置=C:\Users\Desktop\SomeFolder tickerNames=C:\Users\Desktop\SomeFile.txt

我喜欢访问

 Properties configProp = new Properties();
        String propertyValue = null;
        try {
            InputStream in = PropertyGet.class.getResourceAsStream("/application.properties");
            configProp.load(in);
            propertyValue = configProp.getProperty(propertyName);

无论我尝试什么,当我创建一个可运行的 jar 文件时,它都不会获取文件位置。我需要如何构造文件以便我的可运行 jar 可以找到它们?

谢谢

4

2 回答 2

0

If you try to load it as "/application.properties", it will be loaded from the root of the classpath. That will succeed if you package your properties file into the executable jar you are building.

If you want to side-load the properties file eg. from the same dir as your jar, you can specify a classpath when starting your jar file and make sure the directory gets included where the properties file is.

于 2012-11-14T21:23:39.900 回答
0

The answer is to put the .properties file in your jar, in resources.

于 2012-11-14T21:24:11.530 回答