[ 
https://issues.apache.org/jira/browse/CONFIGURATION-600?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=14557837#comment-14557837
 ] 

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:
/conf/jar-main.xml
/conf/jar-test.properties
/conf/jar-test.properties.xml
/conf/jar-test.xml

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

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):

{code}
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"));
}
{code}

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: https://issues.apache.org/jira/browse/CONFIGURATION-600
>             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
(v6.3.4#6332)

Reply via email to