Search path for "import module"

Thursday, 22 September 2011 · 6 messages
RJ
Ralf Jung22 Sep 2011 13:19 #
Hi list, since my XQuery's share some common utility functions, I created a "global.xq" file to contain those functions, and the actual scripts import that file using import module namespace red-db="red-db" at "global.xq"; However, BaseX then looks for that file in the working directory where it was started. Is there any way to configure that behaviour, e.g. to look into the HTTPPATH folder the script is located in, or maybe to make the lookup relative to the script that contains this command? Currently I always have to cd to the HTTPPATH folder before starting BaseX. I am using the current git master version. Kind regards, Ralf
DP
Dimitar Popov22 Sep 2011 13:28 #
Hi Ralf, well, I guess, this is the default Java behavior, and AFAIK BaseX does not provide such an option (but I need to check). However, you may find that using the packaging API [1] is a much more convenient way of managing XQuery module libraries. Greetings, Dimitar [1] http://docs.basex.org/wiki/Packaging
Quoted text · 13:19:47 · 23 lines
Am Donnerstag, 22. September 2011, 13:19:47 schrieb Ralf Jung: > Hi list, > > since my XQuery's share some common utility functions, I created a > "global.xq" file to contain those functions, and the actual scripts import > that file using > > import module namespace red-db="red-db" at "global.xq"; > > However, BaseX then looks for that file in the working directory where it > was started. Is there any way to configure that behaviour, e.g. to look > into the HTTPPATH folder the script is located in, or maybe to make the > lookup relative to the script that contains this command? Currently I > always have to cd to the HTTPPATH folder before starting BaseX. > > I am using the current git master version. > > Kind regards, > Ralf > _______________________________________________ > BaseX-Talk mailing list > BaseX-Talk at mailman.uni-konstanz.de > https://mailman.uni-konstanz.de/mailman/listinfo/basex-talk
RJ
Ralf Jung22 Sep 2011 14:05 #
Hi Dimitar,
Quoted text · Dimitar Popov · 2 lines
> However, you may find that using the packaging API [1] is a much more > convenient way of managing XQuery module libraries.
This is just a simple xq file with four functions, me being the only user. I don't really want to learn a whole new API and whatnot to get it imported. The relevant code seems to be in QueryParser.io:
    IO fl = IO.get(fn);
    // if file does not exist, try base uri
    if(!fl.exists()) {
      final IO base = ctx.base();
      if(base != null) fl = base.merge(fn);
    }
    // if file does not exist, try query directory
    if(!fl.exists() && file != null) fl = file.merge(fn);
However, both ctx.base() and file are null for the query run though
/rest?run=name.xq, so it does not find the other file.
Kind regards, Ralf
CG
Christian Grünin reply to Ralf Jung, 22 Sep 2011, 13:1922 Sep 2011 14:22 #
Ralf, thanks for the observation. I've got some ideas how to fix it properly. Getting back to you, Christian
Quoted text · Ralf Jung · 23 lines
On Thu, Sep 22, 2011 at 1:19 PM, Ralf Jung <ralfjung-e at gmx.de> wrote: > Hi list, > > since my XQuery's share some common utility functions, I created a "global.xq" > file to contain those functions, and the actual scripts import that file using > > import module namespace red-db="red-db" at "global.xq"; > > However, BaseX then looks for that file in the working directory where it was > started. Is there any way to configure that behaviour, e.g. to look into the > HTTPPATH folder the script is located in, or maybe to make the lookup relative > to the script that contains this command? Currently I always have to cd to the > HTTPPATH folder before starting BaseX. > > I am using the current git master version. > > Kind regards, > Ralf > _______________________________________________ > BaseX-Talk mailing list > BaseX-Talk at mailman.uni-konstanz.de > https://mailman.uni-konstanz.de/mailman/listinfo/basex-talk >
CG
Christian Grünin reply to Ralf Jung, 22 Sep 2011, 13:1922 Sep 2011 15:04 #
Quoted text · Ralf Jung · 7 lines
> since my XQuery's share some common utility functions, I created a "global.xq" > file to contain those functions, and the actual scripts import that file using > > import module namespace red-db="red-db" at "global.xq"; > > However, BaseX then looks for that file in the working directory where it was > started.
..should be fixed; please check out the latest sources.
RJ
Ralf Jung22 Sep 2011 15:13 #
Hi Christian, thanks a lot, it's working :) Kind regards, Ralf
Quoted text · Christian Grün · 11 lines
On Thursday 22 September 2011 15:04:16 Christian Grün wrote: > > since my XQuery's share some common utility functions, I created a > > "global.xq" file to contain those functions, and the actual scripts > > import that file using > > > > import module namespace red-db="red-db" at "global.xq"; > > > > However, BaseX then looks for that file in the working directory where it > > was started. > > ..should be fixed; please check out the latest sources.

⚡Generated with XQuery