Uploaded image for project: 'Commons Configuration'
  1. Commons Configuration
  2. CONFIGURATION-65

[configuration] XMLConfiguration cannot load from a jar

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Resolved
    • Major
    • Resolution: Fixed
    • Nightly Builds
    • None
    • None
    • None
    • Operating System: other
      Platform: All

    • 30702

    Description

      In the current RC1 codebase, the XMLConfiguration class cannot read an xml
      configuration file packaged in a jar file. The PropertiesConfiguration class
      handles this correctly using an InputStream rather than a File object, but the
      XMLConfiguration does not.

      Here is a patch for XMLConfiguration that lets you put XML files into a jar
      file.

      Index: XMLConfiguration.java
      ===================================================================
      RCS file: /home/cvspublic/jakarta-
      commons/configuration/src/java/org/apache/commons/configuration/XMLConfiguration
      .java,v
      retrieving revision 1.10
      diff -u -r1.10 XMLConfiguration.java
      — XMLConfiguration.java 14 Aug 2004 11:32:06 -0000 1.10
      +++ XMLConfiguration.java 16 Aug 2004 21:55:26 -0000
      @@ -19,6 +19,7 @@
      import java.io.File;
      import java.io.FileWriter;
      import java.io.IOException;
      +import java.io.InputStream;
      import java.io.OutputStream;
      import java.io.OutputStreamWriter;
      import java.io.StringWriter;
      @@ -142,20 +143,20 @@
      }

      public void load() throws ConfigurationException {

      • File file = null;
        + InputStream resource = null;
        try { URL url = ConfigurationUtils.getURL(getBasePath(), getFileName()); - file = new File(url.getFile()); + resource = url.openStream(); DocumentBuilder builder = DocumentBuilderFactory.newInstance ().newDocumentBuilder(); - document = builder.parse(file); + document = builder.parse(resource); }

        catch (IOException de)

        { - throw new ConfigurationException("Could not load from " + file.getAbsolutePath(), de); + throw new ConfigurationException("Could not load from " + getFileName(), de); }

        catch (ParserConfigurationException ex)

        { throw new ConfigurationException("Could not configure parser", ex); }

        catch (FactoryConfigurationError ex)

        { throw new ConfigurationException("Could not create parser", ex); }

        catch (SAXException ex)

        { - throw new ConfigurationException("Error parsing file " + file.getAbsolutePath(), ex); + throw new ConfigurationException("Error parsing file " + getFileName(), ex); }

      initProperties(document.getDocumentElement(), new StringBuffer());

      Attachments

        Activity

          People

            Unassigned Unassigned
            jromanda@infophase.com J.C. Romanda
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: