5

I have a class called XMLtoXML.java and this is one of it's methods...

import org.dom4j.Document;
import org.dom4j.Element;
import org.dom4j.Node;
import org.dom4j.io.OutputFormat;
import org.dom4j.io.XMLWriter;

public Object[] process(Object data) {

    String templateXML = null;
    Object result[] = null;
    String inputxml = null;
    String templateNumber = null;
    Iterator iterator = null;
    String scenarioConfigUrl = null;
    Node inputNode;
    Node outputNode;
    String subTemplateXML = null;
    String outputXml = null;

    if (delay != null) {

        long time = Long.parseLong(delay);
        try {
            Thread.sleep(time);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }
    inputxml = (String) metadata.get(Constants.REQUEST);
    if (inputxml == null) {
        throw new NullRecordException("input data to XMLtoXML class  in   
      metadata map is null");
    }
    Document inputXMLDocument = Dom4jUtils.getDocument(inputxml);

last line of code block uses a dom4j Document.i have dom4j-full.jar in my classpath. if i run this class as standalone(Run as Java application in eclipse) then it works fine. when i add this class as part of web appllication and dom4j-full.jar in my classpath.
i got following exception.

java.lang.NoClassDefFoundError: org/dom4j/Document
   at org.jaxen.dom4j.DocumentNavigator.getDocumentNode(DocumentNavigator.java:346)
   at org.jaxen.expr.DefaultAbsoluteLocationPath.evaluate
    (DefaultAbsoluteLocationPath.java:102)

   at org.jaxen.expr.DefaultXPathExpr.asList(DefaultXPathExpr.java:102)
   at org.jaxen.BaseXPath.selectNodesForContext(BaseXPath.java:674)
   at org.jaxen.BaseXPath.selectNodes(BaseXPath.java:213)
   at org.jaxen.BaseXPath.selectSingleNode(BaseXPath.java:234)
   at org.dom4j.xpath.DefaultXPath.selectSingleNode(DefaultXPath.java:156)
   at org.dom4j.tree.AbstractNode.selectSingleNode(AbstractNode.java:188)
   at org.amdocs.convert.XMLtoXML.process(XMLtoXML.java:134)
   at org.openadaptor.core.node.Node.processSingleRecord(Node.java:148)
   at org.openadaptor.core.node.Node.process(Node.java:170)
   at org.openadaptor.core.node.ProcessorNode.process(ProcessorNode.java:96)
   at org.openadaptor.core.router.AbstractRouter.process(AbstractRouter.java:239)
   at org.openadaptor.core.router.AbstractRouter.process(AbstractRouter.java:223)
   at org.openadaptor.core.router.AbstractRouter.processResponse(AbstractRouter.java:249)
   at org.openadaptor.core.router.AbstractRouter.process(AbstractRouter.java:239)
   at org.openadaptor.core.router.AbstractRouter.process(AbstractRouter.java:223)
   at org.openadaptor.core.router.AbstractRouter.process(AbstractRouter.java:180)
   at org.openadaptor.core.adaptor.Adaptor.process(Adaptor.java:285)
   at org.openadaptor.core.node.Node.callChainedMessageProcessor(Node.java:213)
   at org.openadaptor.core.node.Node.process(Node.java:199)
   at org.openadaptor.core.node.ReadNode.process(ReadNode.java:241)
   at org.openadaptor.core.node.ReadNode.run(ReadNode.java:196)
   at java.lang.Thread.run(Thread.java:619)

I am also sure that the dom4j jar present on classpath. Anybody have any ideas about issue?

Vadzim
  • 24,954
  • 11
  • 143
  • 151
sa9689
  • 65
  • 1
  • 2
  • 7
  • 1
    Well, how have you tried to include dom4j-full.jar in your classpath? It sounds like it really *isn't* there - or at least isn't accessible to `jaxen`. Where is `jaxen` on your classpath? – Jon Skeet Jan 25 '12 at 11:41
  • Use my [classfinder](http://www.adarshr.com/papers/classfinder) to search which jar(s) contains a given class. – adarshr Jan 25 '12 at 11:47
  • @JonSkeet Dom4j seems to be there at the beginning if you look at the stacktrace, but nomore when jaxen looks up the `Document` class. That's weird! – javanna Jan 25 '12 at 11:48
  • 1
    @javanna: It's not particularly weird if jaxen is in some "global" classloader but dom4j is only in the webapp's lib directory, for example. – Jon Skeet Jan 25 '12 at 12:06
  • @JonSkeet of course, in that case is just weird having them in different locations :) – javanna Jan 25 '12 at 12:15
  • @JonSkeet Looks like the accepted answer is not only mine, thank you for your hint! – javanna Jan 25 '12 at 14:47

2 Answers2

4

Looks like dom4j-full.jar contains both dom4j and jaxen. From you stacktrace I understand dom4j is in the classpath, and it can find jaxen, but when jaxen looks for dom4j it can't find it. I think the jaxen that has been loaded from dom4j isn't for some reason that one inside the dom4j-full.jar but another one that you have within your application server classpath (and not in your eclipse of course), perhaps loaded from a different classloader. Maybe you have a jaxen.jar in your shared libraries or something like this.

javanna
  • 59,145
  • 14
  • 144
  • 125
  • 2
    thanks javanna. that's issue. i am using weblogic. Jaxen is part of weblogic System Classpath, so it does not see my jars. I have define PREFER WEB INF classes option in weblogic.xml for my WAR file. This way I ensured that dom4j-full.jar are loaded for dom4j and jaxen. – sa9689 Jan 25 '12 at 14:11
3

The stacktrace clearly states that other org.dom4j classes are present and being used. So it seems you have library version conflict.

dom4j and jaxen versions should be compatible with each other.

Compare their versions with those that work well in standalone mode.

Vadzim
  • 24,954
  • 11
  • 143
  • 151
  • most likely. `NoClassDefFound`'s can be a bitch to track down – jere Jan 25 '12 at 12:07
  • @Vadzim,i have used same jar in standalone and web application (dom4j-full.jar). i think it may be classloader issue but i am not sure. – sa9689 Jan 25 '12 at 13:13
  • Is jaxen also the same? If it is, then see comment by Jon Skeet. Check that both jars are in the same place and there is no doubles. – Vadzim Jan 25 '12 at 13:31