1

I am using Apache Commons Configuration to keep some properties in a properties file located in a package re/iprocu/coperativeerp/config/payment/configurations.properties

private PropertiesConfiguration configs = new  PropertiesConfiguration("re/iprocu/coperativeerp/config/payment/configurations.properties");
configs.setAutoSave(true);
configs.setProperty(date.getYear()+"-"+date.getMonthValue()+"-01", offsetMember);

The problem is when i run the above code i get the following error

Exception in thread "JavaFX Application Thread" org.apache.commons.configuration.ConfigurationRuntimeException: Failed to auto-save
at org.apache.commons.configuration.AbstractFileConfiguration.possiblySave(AbstractFileConfiguration.java:753)
at org.apache.commons.configuration.AbstractFileConfiguration.clearProperty(AbstractFileConfiguration.java:799)
at org.apache.commons.configuration.AbstractConfiguration.setProperty(AbstractConfiguration.java:485)
at org.apache.commons.configuration.AbstractFileConfiguration.setProperty(AbstractFileConfiguration.java:788)

Update

Apache Commons Configuration V. 1.10

Maven dependency

<dependency>
     <groupId>commons-configuration</groupId>
     <artifactId>commons-configuration</artifactId>
     <version>1.10</version>
</dependency>
Yunus Einsteinium
  • 1,102
  • 4
  • 21
  • 55

2 Answers2

1

You cannot save a configuration that points to a file within a JAR. Try using a configuration file that is located outside of your JAR and you'll see that auto-save option works correctly.

EDIT

You can put the file both in a JAR and in the same relative path in one of the default locations. Here's what the documentation says.

If you do not specify an absolute path, the file will be searched automatically in the following locations:

  • in the current directory
  • in the user home directory
  • in the classpath

So, if for instance you have a default properties file in you JAR, located at conf/configuration.properties, you can put the properties either in user's home directory under the same relative path - e.g. on Linux /home/username/conf/configuration.properties or in the same directory with your JAR file. Both should be secure enough.

Community
  • 1
  • 1
Miloš Milivojević
  • 5,219
  • 3
  • 26
  • 39
  • Then the big question is where to keep the properties file(the location should be relative path and sure that there will be no security issues with it) ? – Yunus Einsteinium Aug 14 '16 at 10:44
1

That issue can be connected with inproper version of commons configuration. I had exactly same dependency in my pom and problems arose from it. What I've done is included such dependencies instead

    <dependency>
        <groupId>org.apache.commons</groupId>
        <artifactId>commons-configuration2</artifactId>
        <version>2.8.0</version>
    </dependency>

    <dependency>
        <groupId>commons-beanutils</groupId>
        <artifactId>commons-beanutils</artifactId>
        <version>1.9.3</version>
    </dependency>

Commons-configuration2 uses commons-beanutils which is optional, that is why I've also included second dependency.

kmat
  • 21
  • 4