I'm trying to do a custom XSLT transformation using Ant 1.3 and Xalan
2.0.  I followed the Xalan DOM2DOM example and incorporate it into a
Task as attached.  However, I got this error:

BUILD FAILED
 
java.lang.LinkageError: loader constraints violated when linking
org/w3c/dom/Node class
        at
com.sendmail.gui.vcube.ant.tasks.DummyCompile.execute(DummyCompile.java:72)
        at org.apache.tools.ant.Target.execute(Target.java:153)
        at org.apache.tools.ant.Project.runTarget(Project.java:898)
        at org.apache.tools.ant.Project.executeTarget(Project.java:536)
        at org.apache.tools.ant.Project.executeTargets(Project.java:510)
        at org.apache.tools.ant.Main.runBuild(Main.java:421)
        at org.apache.tools.ant.Main.main(Main.java:149)

        Total time: 10 seconds
        loader constraints violated when linking org/w3c/dom/Node
class                 

At first I thought it's a classpath error.  I tried to write a custom
script that includes ONLY classpath with xalan.jar, xerces.jar, ant.jar,
and optional.jar when I invoke Ant.  This doesn't work, however.  I
still get the aboved error on the line:

                DOMSource domSource = new DOMSource(doc);

The strange thing is, when I copy over the DOM2DOM.java sample, compile,
and run it inside Ant I actually get it to work using the same
classpath.  Can somebody tell me what's going wrong?


Will

P.S. Here is what the Dummy class look like, which is almost an exact
copy of the DOM2DOM.java wrapped in a Task:

package com.sendmail.gui.vcube.ant.tasks;


// Imported TraX classes
import javax.xml.transform.TransformerFactory;
import javax.xml.transform.Transformer;
import javax.xml.transform.stream.StreamSource;
import javax.xml.transform.stream.StreamResult;
import javax.xml.transform.TransformerException;
import javax.xml.transform.TransformerConfigurationException;
import javax.xml.transform.dom.DOMSource;
import javax.xml.transform.dom.DOMResult;

// Imported SAX classes
import org.xml.sax.InputSource;
import org.xml.sax.SAXException;

// Imported DOM classes
import org.w3c.dom.Document;
import org.w3c.dom.Node;

// Imported Serializer classes
import org.apache.xalan.serialize.Serializer;
import org.apache.xalan.serialize.SerializerFactory;

import org.apache.xalan.templates.OutputProperties;

// Imported JAVA API for XML Parsing classes
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException; 

import org.apache.tools.ant.Task;
import org.apache.tools.ant.BuildException;

public class DummyCompile extends Task {

    public DummyCompile() {
    } //-- DummyCompile

    /**
     * Executes the task.
     */

    public void execute() throws BuildException {
        try 
        {    
            TransformerFactory tFactory =
TransformerFactory.newInstance();

            if(tFactory.getFeature(DOMSource.FEATURE) &&
tFactory.getFeature(DOMResult.FEATURE))
            {
                // Process the stylesheet StreamSource and generate a
Transformer.
                Transformer transformer = tFactory.newTransformer(new
StreamSource("birds.xsl"));

                //Instantiate a DocumentBuilderFactory.
                DocumentBuilderFactory dFactory =
DocumentBuilderFactory.newInstance();

                //Use the DocumentBuilderFactory to create a
DocumentBuilder.
                DocumentBuilder dBuilder =
dFactory.newDocumentBuilder();

                //Use the DocumentBuilder to parse the XML input.
                Document doc = dBuilder.parse("birds.xml");

                // Use the DOM Document to define a DOMSource object.
                DOMSource domSource = new DOMSource(doc);

                // Set the base URI for the DOMSource so any relative
URIs it contains can
                // be resolved.
                domSource.setSystemId("birds.xml");

                // Create an empty DOMResult for the Result.
                DOMResult domResult = new DOMResult();

                // Perform the transformation, placing the output in the
DOMResult.
                transformer.transform(domSource, domResult);

                //Instantiate an XML serializer and use it to serialize
the output DOM to System.out
                // using a default output format.
                Serializer serializer = SerializerFactory.getSerializer
                   
(OutputProperties.getDefaultMethodProperties("xml"));
                serializer.setOutputStream(System.out);
               
serializer.asDOMSerializer().serialize(domResult.getNode());
            }
            else
            {
                throw new org.xml.sax.SAXNotSupportedException("DOM node
processing not supported!");
            }
        } catch (Exception e)
        {
            throw new BuildException("error");
        }
    } //-- execute

} //-- DummyCompile

Reply via email to