[問題] 關於dom4的NoClassDefoundError..
小弟不才, 利用xml書籍附的程式碼來測試xml文件
dom4j的程式碼如下:
import org.dom4j.*;
import org.dom4j.io.*;
import java.io.*;
import java.util.*;
public class XPathDemo
{
public static void main(String[] args)
{
try
{
SAXReader reader = new SAXReader();
Document doc = reader.read(new File("bookshelf.xml"));
// get XPath
XPath xpath = DocumentHelper.createXPath("/bookshelf/level/book");
List list = xpath.selectNodes(doc);
for(int i = 0; i < list.size(); i++)
{
System.out.println("Book " + (i+1));
Element el = (Element)list.get(i);
// get childen of element book
Iterator it = el.elementIterator();
while(it.hasNext())
{
Element childEl = (Element)it.next();
System.out.println(childEl.getName() + ": " + childEl.getText());
}
}
}
catch(DocumentException e)
{
// error in the XML document
System.out.println(e);
}
catch(Exception e)
{
System.out.println(e);
}
}
}
xml的程式碼如下:
<?xml version="1.0" encoding="ISO-8859-1"?>
<!-- My Bookshelf -->
<bookshelf>
<level name="Physics">
<book><title>Mechanics</title>
<author>Symon</author>
</book>
<book><title>Optics</title>
<author>Hecht</author>
</book>
</level>
<level name="Math">
<book><title>Principles of Mathematical Analysis</title>
<author>Rudin</author>
</book>
<book><title>Linear Algebra</title>
<author>Lang</author>
</book>
</level>
</bookshelf>
因為是書的光碟附的程式碼...所以應不至於有錯
我有去dom4j的官網下載dom4j.jar放在C:\java\j2sdk1.4.5\jre\lib\ext
但是還是發生"NoDefoundClassError"
有人說是因為要使用"dom4j-full.jar" package才能正常執行
但是我在官網根本看不到有dom4j-full.jar載點
拜託救救我吧><
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 218.161.7.138
討論串 (同標題文章)
以下文章回應了本文 (最舊先):
完整討論串 (本文為第 1 之 5 篇):
java 近期熱門文章
PTT數位生活區 即時熱門文章