The following text is extracted from the eXist documentation .
For example, a typical import statement in an XQuery will look like this:
import module namespace status="http://exist-db.org/xquery/admin-interface/status" at "http://exist-db.org/modules/test.xqm";
Provided that the module namespace does not point to one of the preloaded standard modules (see below), the query engine will try to locate the module source by looking at the URI given after the at keyword.
If I use a script that imports a module from a disk file specified as a file URI, eXist fails to load it.
import module namespace my="urn:my-functions" at "file:///home/user/my-module.xq";
The problem seems to be in the org.exist.source.SourceFactory class. SourceFactory#getSource(broker, contextPath, location, boolean):Source is used to create a Source object for a specified location in org.exist.xquery.XQueryContext#importModule(XQueryContextString namespaceURI, String prefix, String location).
If that location starts with "file:", a FileSource is created but the path is parsed incorrectly using a regular expression.
location = location.replaceAll("^(file:)?/(.)$", "$2");
This means that if it receives the location "file:///home/user/my-module.xq", it creates a FileSource for "home/user/my-module.xq" which is not correct. Also, if the file URI contains spaces encoded as %20, it also fails to create the file correctly.
A work-around is to put a space before the file URI so that SourceFactory creates a URLSource instead of a FileSource.
import module namespace my="urn:my-functions" at " file:///home/user/my-module.xq";