I don't seem to be reading external file from jar when on linux

The following code works fine on windows:

private static Properties getProps() throws FileNotFoundException, IOException {
    Properties properties = new Properties();
    File externalFile = new File("myProp.properties");

    if(externalFile.exists()) //if an external property file exists within the same path it is prioritized
        properties.load(new FileInputStream(externalFile));
    else{
        properties.load(CommandUtil.class.getClass().getResourceAsStream("/com/localpath/default.properties"));
    }
    return properties;
}

      

if myProp.properties exists in the same .jar folder then this property file is read, otherwise the default .properties file contained within the .jar itself will be executed.

When I move this program on a Linux system it doesn't work anymore: even if there is a .properties file next to the .jar, it is simply ignored. Why is this?

+3


source to share





All Articles