Commons Configuration
  1. Commons Configuration

[configuration] ConfigurationFactory loading from classpath issue


    • Type: Bug Bug
    • Status: Resolved
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: None
    • Component/s: None
    • Labels:
    • Environment:

      Operating System: All
      Platform: All


      I found a thread on the commons mailing list about this topic, but did not see a
      resolution presented.

      It seems the only way to load a properties file from a separate jar in the
      classpath is to use absolute paths. I believe the ConfigurationFactory
      framework would be a tad more useful if it used the classloader to load the
      properties files as resources instead. The major advantage being that one could
      package a default properties file in a config jar, but temporarily override it
      by placing a copy higher in the classpath. There are other uses as well, but
      that's the main use case I have in mind right now.

      Let's say I have the following JAR that contains only these configuration files:

      properties/config.xml <= The ConfigurationFactory settings
      properties/test-config.xml <= An XML properties file

      com.test.ConfigurationTest <= Constructs ConfigurationFactory and calls

      Because I use the classload to load

      <!-- config.xml -->
      <xml fileName="test-config.xml"/>

      I have tried many variations of the above path to get it to load from the
      classpath to no avail, such as:

      <xml fileName="properties/test-config.xml"/>
      <xml fileName="/properties/test-config.xml"/>
      <xml fileName="file:test-config.xml"/>
      <xml fileName="file:properties/test-config.xml"/>
      <xml fileName="file:/properties/test-config.xml"/>

      Most of the time it coughs out a SAXException with a garbled path like this:

      Could not load from
      at org.apache.commons.digester.Digester.createSAXException(
      at org.apache.commons.digester.Digester.createSAXException(
      at org.apache.commons.digester.Digester.endElement(

      In other words, I can't seem to make it use the appropriate URL for accessing
      the file when it's in another JAR.


      If I move the properties folder to the JAR that contains the test class, it
      works fine. I believe I could also use an absolute path to the properties file,
      but again, that precludes me from being able to quickly override the properties
      file by placing a copy higher in the classpath.

      This is my first experience with trying to initiate a change in an open source
      project, so bear with me if I'm not following the right protocol. I'd like to
      take a stab at creating a patch myself if someone hasn't already beat me to it.



        Joe Holloway created issue -
        Henri Yandell made changes -
        Field Original Value New Value
        issue.field.bugzillaimportkey 30856 12341659
        Henri Yandell made changes -
        Project Commons [ 12310458 ] Commons Configuration [ 12310467 ]
        Affects Version/s unspecified [ 12311647 ]
        Component/s Configuration [ 12311107 ]
        Key COM-1507 CONFIGURATION-47
        Assignee Jakarta Commons Developers Mailing List [ ]


          • Assignee:
            Joe Holloway
          • Votes:
            0 Vote for this issue
            1 Start watching this issue


            • Created: