我正在进行Xquery JUnit测试,代码上没有错误,但是在运行时会启动此异常:
java.lang.NoSuchMethodError: net.sf.saxon.Configuration.newConfiguration()Lnet/sf/saxon/Configuration;
at net.sf.saxon.xqj.SaxonXQDataSource.<init>(SaxonXQDataSource.java:38)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:526)
at java.lang.Class.newInstance(Class.java:374)
at ...cat.udl.eps.softarch.hello.XMLConnectionTest.staticFileTest(XMLConnectionTest.java:85)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:47)
...
这是测试:
@Test
public void staticFileTest() throws ClassNotFoundException, IllegalAccessException, InstantiationException, XQException, FileNotFoundException {
XQPreparedExpression expr;
XQConnection conn;
//TODO Change local path file
InputStream testFile = new FileInputStream("C:\\Users\\...\\testXML.xml");
String xqueryString =
" declare variable $doc external;\n" +
"for $x in $doc return $x//acte/nom/text()";
XQDataSource xqds = (XQDataSource)Class.forName("net.sf.saxon.xqj.SaxonXQDataSource").newInstance();
conn = xqds.getConnection();
expr = conn.prepareExpression(xqueryString);
expr.bindDocument(new javax.xml.namespace.QName("doc"), testFile, null, null);
XQResultSequence rs = expr.executeQuery();
System.out.println("test:");
while(rs.next())
System.out.println(rs.getItemAsString(null));
assertNotNull(rs);
conn.close();
}
它可能是图书馆的问题?我添加了Maven:net.sourceforge.saxon:saxon:9.1.0.8 和net.sf.saxon:Saxon-HE:9.4