JDom解析xml文件的java.lang.NoClassDefFoundError问题








java代码为:
import java.io.IOException;
import java.util.List;

import org.jdom.Document;
import org.jdom.Element;
import org.jdom.JDOMException;
import org.jdom.input.SAXBuilder;
import org.jdom.xpath.XPath;


public class Sample1 {    
    public static void main(String []args){
        SAXBuilder sb=new SAXBuilder();
        Document doc=null;
        try {
            doc = sb.build("src/applicationContext.xml");
            
        } catch (JDOMException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        System.out.println(doc);
        Element root=doc.getRootElement();
        System.out.println(root);
        try {
            List list=XPath.selectNodes(root, "/beans/bean");
        } catch (JDOMException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        
    }
}
运行时为什么总出现下面问题:
Exception in thread "main" java.lang.NoClassDefFoundError: org/jaxen/JaxenException
    at java.lang.Class.forName0(Native Method)
    at java.lang.Class.forName(Unknown Source)
    at org.jdom.xpath.XPath.newInstance(XPath.java:134)
    at org.jdom.xpath.XPath.selectNodes(XPath.java:345)
    at cn.xml.jdom.demo.Sample1.main(Sample1.java:33)
解决:
包不全造成的吧,jdom依赖4个包jaxen.jar,xalan.jar,xerces.jar,xml-apis.jar,下载jdom时在解压后的lib下

你可能感兴趣的:(常见问题,xml,exception,encoding,class,list,thread)