commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Thomas Mortagne <thomas.morta...@gmail.com>
Subject Re: [configuration] Creating a properties file
Date Wed, 30 Aug 2017 08:56:50 GMT
Here is what I currently do:

            PropertiesBuilderParameters parameters = new
Parameters().properties();
            if (file.exists()) {
                new Parameters().properties().setFile(file);
            }

            FileBasedConfigurationBuilder<PropertiesConfiguration> builder =
                new
FileBasedConfigurationBuilder<PropertiesConfiguration>(PropertiesConfiguration.class)
                    .configure(parameters);
            PropertiesConfiguration properties = builder.getConfiguration();

            properties.setProperty("property", "value");

            builder.getFileHandler().save(file);

but I find it more complex than it should.

IMO the file handler should not care if the file exist or not by
default (empty PropertiesConfiguration as in 1.x if it does not exist)
and only fail if asked to in the parameters of the builder. At the
very least it should be possible to have some way to tell the builder
to not care about not existing file.

On Wed, Aug 30, 2017 at 10:37 AM, Thomas Mortagne
<thomas.mortagne@gmail.com> wrote:
> Hi,
>
> I trying to move from Commons Configuration 1.x to 2.1.1 and I cannot
> figure out how to do something that used to be obvious: creating a
> properties file that does not yet exist on the file system.
>
> In 1.x all I had to do is create a PropertiesConfiguration with a
> File, set a few properties and then save.
>
> In 2.1.1 I cannot find how to configure the build for it to accept a
> path to a file that does not exist, I always end up with:
>
> org.apache.commons.configuration2.ex.ConfigurationException: Could not
> locate: org.apache.commons.configuration2.io.FileLocator@28d79cba[fileName=store.properties,basePath=/media/data/projets/xwiki/src/git/xwiki-commons/xwiki-commons-core/xwiki-commons-job/target/test/jobs/status,sourceURL=,encoding=ISO-8859-1,fileSystem=<null>,locationStrategy=<null>]
>     at org.apache.commons.configuration2.io.FileLocatorUtils.locateOrThrow(FileLocatorUtils.java:346)
>     at org.apache.commons.configuration2.io.FileHandler.load(FileHandler.java:972)
>     at org.apache.commons.configuration2.io.FileHandler.load(FileHandler.java:702)
>
> and from what I see in FileHandler sources it not really configurable.
>
> So did I missed something or am I really supposed to create an empty
> file before using the builder ?
>
> Thanks,
> --
> Thomas



-- 
Thomas

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
For additional commands, e-mail: user-help@commons.apache.org


Mime
View raw message