gpt4 book ai didi

java - Apache Commons 配置无法保存

转载 作者:行者123 更新时间:2023-11-30 07:13:44 24 4
gpt4 key购买 nike

我正在使用 Apache Commons Configuration 将某些属性保留在位于包中的属性文件中 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);

问题是当我运行上面的代码时出现以下错误

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)

更新

Apache Commons 配置 V.1.10

Maven 依赖

<dependency>
<groupId>commons-configuration</groupId>
<artifactId>commons-configuration</artifactId>
<version>1.10</version>
</dependency>

最佳答案

您无法保存指向 JAR 中的文件的配置。尝试使用位于 JAR 外部的配置文件,您将看到自动保存选项正常工作。

编辑

您可以将文件放入 JAR 中,也可以放入默认位置之一的同一相对路径中。这就是 the documentation说。

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

因此,如果您的 JAR 中有一个默认属性文件(位于 conf/configuration.properties),您可以将这些属性放在用户主目录中的同一相对路径下 - 例如在 Linux 上 /home/username/conf/configuration.properties 或与 JAR 文件位于同一目录中。两者都应该足够安全。

关于java - Apache Commons 配置无法保存,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38769198/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com