使用 dom4j 解析 XML/GML 時調用 root.selectNodes("featureMember") 拋出:
java.lang.NoClassDefFoundError: org/jaxen/JaxenException
at org.dom4j.DocumentFactory.createXPath(DocumentFactory.java:230)
at org.dom4j.tree.AbstractNode.createXPath(AbstractNode.java:207)
at org.dom4j.tree.AbstractNode.selectNodes(AbstractNode.java:164)
...
dom4j 的 XPath 功能(selectNodes、selectSingleNode)依賴 Jaxen 庫作為 XPath 引擎。異常鏈顯示 ClassNotFoundException: org.jaxen.JaxenException,表明 classpath 缺少 jaxen.jar。
jaxen-1.1.6.jar(或與 dom4j 版本匹配的版本)。<dependency><groupId>jaxen</groupId><artifactId>jaxen</artifactId><version>1.1.6</version></dependency>implementation 'jaxen:jaxen:1.1.6'WEB-INF/lib 或模塊依賴庫。再次執行 XPath 查詢,異常消失,節點列表正常返回。
dom4j:dom4j:2.x,Jaxen 為可選依賴,必須手動添加。