Issue
I am trying to run this code but I get the following error.
package practicaXML;
import javax.xml.xquery.*;
import org.w3c.dom.Node;
import net.xqj.basex.BaseXXQDataSource;
public class App {
public static void main(String[] args) {
try {
XQDataSource xqs = new BaseXXQDataSource();
xqs.setProperty("serverName", "localhost");
xqs.setProperty("port", "1984");
xqs.setProperty("databaseName", "facts");
XQConnection conn = xqs.getConnection("admin", "admin");
String xqueryString = "//province[contains(@name, 'x')]";
XQExpression xqe = conn.createExpression();
XQResultSequence rs = xqe.executeQuery(xqueryString);
Node n;
while(rs.next()) {
n = rs.getNode();
System.out.println(n.getAttributes().getNamedItem("name").getNodeValue());
}
conn.close();
} catch (Exception e) {
System.out.println("Error: " + e.getMessage());
}
}
}
Console:
Error: Unable to initialize main class practicaXML.App
Caused by: java.lang.NoClassDefFoundError: javax/xml/xquery/XQDataSource
It is my first time working with basex and xpath and I have no idea what could be causing this or how to fix it.
Solution
You are missing dependencies. Add dependencies to the classpath or maven repository
Answered By - user895565
Answer Checked By - Gilberto Lyons (JavaFixing Admin)