commons-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Oliver Heger (JIRA)" <>
Subject [jira] [Commented] (CONFIGURATION-600) Loading xml configuration file as a stream does not work with multi configurations
Date Sun, 24 May 2015 20:32:17 GMT


Oliver Heger commented on CONFIGURATION-600:

Finally I managed to look into this. I tried to simulate your use case and created a jar with
a structure similar to the one you described:

The first file is the combined configuration definition file with the following content:
  <properties fileName="" config-name="props"/>
  <properties fileName=""/>
  <xml fileName="jar-test.xml" config-name="xml"/>

This file - and all the referenced configuration sources - could be loaded successfully with
the following code fragement (this uses Commons Configuration 2.0alpha; {{CombinedConfigurationBuilder}}
corresponds to {{DefaultConfigurationBuilder}} in 1.x):

public void testReadFromJar() throws MalformedURLException, ConfigurationException {
    URL url = new URL("jar:file:src/test/resources/config.jar!/conf/jar-main.xml");
    builder.configure(new Parameters().fileBased().setURL(url));
    CombinedConfiguration configuration = builder.getConfiguration();
    assertTrue("Not loaded", configuration.getBoolean("configuration.loaded"));

So rather than loading the file from a stream, I used the URL directly. (Here it is hard-coded,
but of course, it can be obtained via getClassLoader().getResource().) Then relative paths
referenced from the main configuration file are automatically resolved; there is no need to
set a base path. When reading the file from a stream, however, there is no absolute path which
could be used for resolving files.

Maybe this use case can be explicitly mentioned in the documentation. But otherwise, I do
not think that this is a bug or requires a fix in the code base.

> Loading xml configuration file as a stream does not work with multi configurations
> ----------------------------------------------------------------------------------
>                 Key: CONFIGURATION-600
>                 URL:
>             Project: Commons Configuration
>          Issue Type: Bug
>    Affects Versions: 1.8
>            Reporter: John Henriksson
> When using the commons configuration inside a WAR loading a XML file works fine when
done like this:
> InputStream is = this.getClass().getClassLoader().getResourceAsStream("/conf/main.xml");
> builder.load(is);
> The problem is when the main.xml reference other xml files:
> configuration>
>     <xml fileName="child1.xml"/>
> </configuration>
> If the structure of the war is:
> /
> /classes
> /conf/child1.xml
> /conf/main.xml
> There seems to be no way to pick up child1.xml from main.xml when loading main.xml as
a stream.

This message was sent by Atlassian JIRA

View raw message