DTD not found error while updating attribute value using Ant XmlTask

1k views Asked by At

I want to update value of debug.classpath property. I am using XmlTask to do manipulations. However, I am running to DTD not found issue.

This is my target XML file.

<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE Configuration SYSTEM "xconf.dtd">
<Configuration>
     <Property name="debug.classpath" value="<changeme>"
</Configuration>

This is my Ant target.

<target name="configure" >
      <xmltask source="myxml.xml">
            <attr path="//Property[@name='debug.classpath']" attr="value"  value="New Value"/>
      </xmltask>    
</target>

When I execute this target, I get below error.

[xmltask] java.io.FileNotFoundException: D:\utils\xconf.dtd (The system cannot find the file specified)

This DTD is present in a Jar file called Utils.jar. After google'ing I found XmlCatalog task and using that I wrote below version of my target.(Not sure if I've made intended use of XmlCatalog). The Utils.jar is not in Ant's classpath hence tried to add it using <classpath>.

<target name="configure">
    <xmlcatalog id="XconfDtd">
        <classpath>
            <pathelement location="D:/libs/Utils.jar"/>
        </classpath>
        <dtd location="xconf.dtd" />
    </xmlcatalog>
    <xmltask source="${env.WT_HOME}/codebase/wt.properties.xconf">
        <xmlcatalog refid="XconfDtd" />
        <attr path="//Property[@name='debug.classpath']" attr="value" value="New Value" />
    </xmltask>
</target>

However, when I execute this target, I get below error

[xmltask] java.lang.NullPointerException [xmltask] at org.apache.tools.ant.types.XMLCatalog.findMatchingEntry(XMLCatalog.java:592) [xmltask] at org.apache.tools.ant.types.XMLCatalog.access$000(XMLCatalog.java:119) [xmltask] at org.apache.tools.ant.types.XMLCatalog$InternalResolver.resolveEntity(XMLCatalog.java:811) [xmltask] at org.apache.tools.ant.types.XMLCatalog.resolveEntity(XMLCatalog.java:385) [xmltask] at com.sun.org.apache.xerces.internal.util.EntityResolverWrapper.resolveEntity(EntityResolverWrapper.java:110) [xmltask] at com.sun.org.apache.xerces.internal.impl.XMLEntityManager.resolveEntityAsPerStax(XMLEntityManager.java:994) [xmltask] at com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl$DTDDriver.dispatch(XMLDocumentScannerImpl.java:1149) [xmltask] at com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl$DTDDriver.next(XMLDocumentScannerImpl.java:1047) [xmltask] at com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl$PrologDriver.next(XMLDocumentScannerImpl.java:960) [xmltask] at com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl.next(XMLDocumentScannerImpl.java:607) [xmltask] at com.sun.org.apache.xerces.internal.impl.XMLNSDocumentScannerImpl.next(XMLNSDocumentScannerImpl.java:116) [xmltask] at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanDocument(XMLDocumentFragmentScannerImpl.java:488) [xmltask] at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:835) [xmltask] at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:764)

Even after putting Utils.jar to $ANT_HOME/lib I still see above error. Any help is highly appreciated. You can suggest any alternate way to achieve this in Ant.

Thanks in advance.

0

There are 0 answers