Xquery与SaxonXQDataSource:NoSuchMethodError

时间:2014-12-29 11:15:13

标签: maven exception xquery saxon nosuchmethoderror

我正在进行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

1 个答案:

答案 0 :(得分:0)

Saxon 9.1.0.8不包含相关方法,Saxon-HE 9.4也不包含。当你拥有后者的任何最新版本时,你不应该需要前者。删除两者并使用较新版本的Saxon-HE,最好是最新版本。

最新版本应包含here所示的方法。您可以找到版本详细信息here