You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@ant.apache.org by William Lee <wl...@sendmail.com> on 2001/03/06 23:12:09 UTC

org.w3c.dom.Nodes link error when using Ant + Xalan 2.0?

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

Re: org.w3c.dom.Nodes link error when using Ant + Xalan 2.0?

Posted by William Lee <wl...@sendmail.com>.
Let me see  if I understand you correctly.  If I have the task in the
foo.jar and my tasks depends on xalan.jar, xerces.jar, ant.jar, and
optional.jar.  I should put the those jars in the CLASSPATH (the
classplath that I invoke Ant from) and not the foo.jar?  It seems to be
what I'm doing.  What is the classpath I should set when I do a taskdef
then?

Will

Peter Donald wrote:
> 
> At 02:12  6/3/01 -0800, William Lee wrote:
> >At first I thought it's a classpath error.
> 
> I think it still is ;)
> 
> >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.
> 
> this works as a completely new classloader is created.
> 
> >Can somebody tell me what's going wrong?
> 
> Odd classpath behaviour. If you need to load a task then any dependent
> classes have to be in classloader or parent classloaders. So make sure that
> the task is NOT in normal CLASSPATH if its dependent jars are in supplied
> classpath.
> 
> Also double check the ext dirs, ant/lib dir and any other similar dir for
> stray jars.
> 
> Cheers,
> 
> Pete
> 
> *-----------------------------------------------------*
> | "Faced with the choice between changing one's mind, |
> | and proving that there is no need to do so - almost |
> | everyone gets busy on the proof."                   |
> |              - John Kenneth Galbraith               |
> *-----------------------------------------------------*

Re: org.w3c.dom.Nodes link error when using Ant + Xalan 2.0?

Posted by Peter Donald <do...@apache.org>.
At 02:12  6/3/01 -0800, William Lee wrote:
>At first I thought it's a classpath error.  

I think it still is ;)

>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.  

this works as a completely new classloader is created.

>Can somebody tell me what's going wrong?

Odd classpath behaviour. If you need to load a task then any dependent
classes have to be in classloader or parent classloaders. So make sure that
the task is NOT in normal CLASSPATH if its dependent jars are in supplied
classpath.

Also double check the ext dirs, ant/lib dir and any other similar dir for
stray jars.

Cheers,

Pete

*-----------------------------------------------------*
| "Faced with the choice between changing one's mind, |
| and proving that there is no need to do so - almost |
| everyone gets busy on the proof."                   |
|              - John Kenneth Galbraith               |
*-----------------------------------------------------*