Java error: Unable to initialize main class


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( {
                n = rs.getNode();

        } catch (Exception e) {
            System.out.println("Error: " + e.getMessage());


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.

Best Solution

You are missing dependencies. Add dependencies to the classpath or maven repository