简体   繁体   中英

Relative Path Issue Eclipse

I have the following properties file

fileLocation=C:\\Users\\Desktop\\SomeFolder tickerNames=C:\\Users\\Desktop\\SomeFile.txt

which I access like

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

No matter what I try, when i create a runnable jar file it just will not pick up the file locations. How do i need to structure the files so that my runnable jar can find them?

Thanks

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.

答案是将.properties文件放入资源的jar中。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM