Location for import modules

Thursday, 15 October 2015 · 5 messages
PS
Paul Swennenhuis15 Oct 2015 16:00 #
Hi, I installed BaseX 8.3 as Tomcat webapp on a Ubuntu server. Everything works fine, including the DBA interface (very much appreciated, thanks for that!) Except one thing: I can't get the import of XQuery modules right. When I import a module in a .xq file, like this: import module namespace lib="My Library" at "library.xq"; BaseX gives me a "[XQST0059] Could not retrieve module '/library.xq' " error. Earlier I installed BaseX on a EC2 instance at Amazon, and there I found that import modules had to be placed in /usr/share/tomcat7 to be found. But that directory does not exist on this server, and even when I create it and place library.xq there it is still not found. I tried placing library.xq in the RESTPATH directory, in the REPOPATH directory, in the home directory of BaseX, but all in vain. I only get it to work when I place library.xq in the root of the server. And that is obviously not something I want to do. Or, alternatively, when I place it in [some directory] and then change the import line to import module namespace lib="My Library" at "[some directory]/library.xq"; In other words, when I change the relative path to an absolute one. But I'd have to do that for all of my XQuery files (a lot!) and, worse, I'd have to change it again if I deploy the .xq files on another server. So, to summarize: in which directory/directories does BaseX try to locate import modules? And what would I have to do to change the default location(s)? Thanks in advance. Paul
CG
Christian Grün15 Oct 2015 16:05 #
Hi Paul,
Quoted text · Paul Swennenhuis · 4 lines
> When I import a module in a .xq file, like this: > import module namespace lib="My Library" at "library.xq"; > BaseX gives me a "[XQST0059] Could not retrieve module '/library.xq' " > error.
By default, modules should be found if they are located in the directory of the importing module. The URI of your module can be requested via the function static-base-uri(). What does it return in your environment? Christian
Quoted text · Paul Swennenhuis · 24 lines
> > Earlier I installed BaseX on a EC2 instance at Amazon, and there I found > that import modules had to be placed in /usr/share/tomcat7 to be found. > But that directory does not exist on this server, and even when I create it > and place library.xq there it is still not found. > I tried placing library.xq in the RESTPATH directory, in the REPOPATH > directory, in the home directory of BaseX, but all in vain. > I only get it to work when I place library.xq in the root of the server. And > that is obviously not something I want to do. > Or, alternatively, when I place it in [some directory] and then change the > import line to > import module namespace lib="My Library" at "[some > directory]/library.xq"; > In other words, when I change the relative path to an absolute one. > But I'd have to do that for all of my XQuery files (a lot!) and, worse, I'd > have to change it again if I deploy the .xq files on another server. > > So, to summarize: in which directory/directories does BaseX try to locate > import modules? > And what would I have to do to change the default location(s)? > > Thanks in advance. > > Paul
PS
Paul Swennenhuis15 Oct 2015 16:13 #
Hi Christian, Thanks for the swift response. I tried to place it in the directory of the importing module as well but that did not work either. When I run this query:
<dirs>
   <currentDir>
   {file:current-dir()}
   </currentDir>
    <baseDir>
   {file:base-dir()}
   </baseDir>
   <baseUri>
   {static-base-uri()}
   </baseUri>
   <parent>
   {file:parent(static-base-uri())}
   </parent>
   <abs>
   {file:path-to-native("/")}
   </abs>
   <files>
   {file:children(".")}
   </files>
</dirs>
the output is:
<dirs>
   <currentDir>/</currentDir>
   <baseDir>/opt/tomcat/webapps/BaseX83/xq/</baseDir>
<baseUri>file:/opt/tomcat/webapps/BaseX83/xq/currentDir.xq</baseUri>
   <parent>/opt/tomcat/webapps/BaseX83/xq/</parent>
   <abs>/</abs>
   <files>./lost+found/ ./media/ ./opt/ ./run/ ./library.xq ./home/
./var/ ./dev/ ./boot/ ./sbin/ ./proc/ ./sys/ ./bin/ ./lib/ ./root/
./vmlinuz ./mnt/ ./usr/ ./lib64/ ./initrd.img ./tmp/ ./srv/ ./etc/</files>
</dirs>
As you can see, the children() of the current directory (.) are server root entries. Paul
Quoted text · Christian Grün · 38 lines
> Hi Paul, > >> When I import a module in a .xq file, like this: >> import module namespace lib="My Library" at "library.xq"; >> BaseX gives me a "[XQST0059] Could not retrieve module '/library.xq' " >> error. > By default, modules should be found if they are located in the > directory of the importing module. > > The URI of your module can be requested via the function > static-base-uri(). What does it return in your environment? > > Christian > > >> Earlier I installed BaseX on a EC2 instance at Amazon, and there I found >> that import modules had to be placed in /usr/share/tomcat7 to be found. >> But that directory does not exist on this server, and even when I create it >> and place library.xq there it is still not found. >> I tried placing library.xq in the RESTPATH directory, in the REPOPATH >> directory, in the home directory of BaseX, but all in vain. >> I only get it to work when I place library.xq in the root of the server. And >> that is obviously not something I want to do. >> Or, alternatively, when I place it in [some directory] and then change the >> import line to >> import module namespace lib="My Library" at "[some >> directory]/library.xq"; >> In other words, when I change the relative path to an absolute one. >> But I'd have to do that for all of my XQuery files (a lot!) and, worse, I'd >> have to change it again if I deploy the .xq files on another server. >> >> So, to summarize: in which directory/directories does BaseX try to locate >> import modules? >> And what would I have to do to change the default location(s)? >> >> Thanks in advance. >> >> Paul
CG
Christian Grün15 Oct 2015 16:17 #
Hm, difficult. If you want, you can provide us with a minimized WAR file of your webapp, and we could do some more testing. Unfortunately, Tomcat regularly caused problems in the past; this is why we are usually working with Jetty or Glassfish in our projects.
Quoted text · Paul Swennenhuis · 97 lines
On Thu, Oct 15, 2015 at 4:13 PM, Paul Swennenhuis <paul at swennenhuis.nl> wrote: > Hi Christian, > > Thanks for the swift response. > I tried to place it in the directory of the importing module as well but > that did not work either. > > > When I run this query: > > <dirs> > <currentDir> > {file:current-dir()} > </currentDir> > <baseDir> > {file:base-dir()} > </baseDir> > <baseUri> > {static-base-uri()} > </baseUri> > <parent> > {file:parent(static-base-uri())} > </parent> > <abs> > {file:path-to-native("/")} > </abs> > <files> > {file:children(".")} > </files> > </dirs> > > > the output is: > > <dirs> > <currentDir>/</currentDir> > <baseDir>/opt/tomcat/webapps/BaseX83/xq/</baseDir> > <baseUri>file:/opt/tomcat/webapps/BaseX83/xq/currentDir.xq</baseUri> > <parent>/opt/tomcat/webapps/BaseX83/xq/</parent> > <abs>/</abs> > <files>./lost+found/ ./media/ ./opt/ ./run/ ./library.xq ./home/ ./var/ > ./dev/ ./boot/ ./sbin/ ./proc/ ./sys/ ./bin/ ./lib/ ./root/ ./vmlinuz ./mnt/ > ./usr/ ./lib64/ ./initrd.img ./tmp/ ./srv/ ./etc/</files> > </dirs> > > > As you can see, the children() of the current directory (.) are server root > entries. > > Paul > > >> Hi Paul, >> >>> When I import a module in a .xq file, like this: >>> import module namespace lib="My Library" at "library.xq"; >>> BaseX gives me a "[XQST0059] Could not retrieve module '/library.xq' " >>> error. >> >> By default, modules should be found if they are located in the >> directory of the importing module. >> >> The URI of your module can be requested via the function >> static-base-uri(). What does it return in your environment? >> >> Christian >> >> >>> Earlier I installed BaseX on a EC2 instance at Amazon, and there I found >>> that import modules had to be placed in /usr/share/tomcat7 to be found. >>> But that directory does not exist on this server, and even when I create >>> it >>> and place library.xq there it is still not found. >>> I tried placing library.xq in the RESTPATH directory, in the REPOPATH >>> directory, in the home directory of BaseX, but all in vain. >>> I only get it to work when I place library.xq in the root of the server. >>> And >>> that is obviously not something I want to do. >>> Or, alternatively, when I place it in [some directory] and then change >>> the >>> import line to >>> import module namespace lib="My Library" at "[some >>> directory]/library.xq"; >>> In other words, when I change the relative path to an absolute one. >>> But I'd have to do that for all of my XQuery files (a lot!) and, worse, >>> I'd >>> have to change it again if I deploy the .xq files on another server. >>> >>> So, to summarize: in which directory/directories does BaseX try to locate >>> import modules? >>> And what would I have to do to change the default location(s)? >>> >>> Thanks in advance. >>> >>> Paul > >
PS
Paul Swennenhuis15 Oct 2015 16:27 #
Hi Christian, Well, actually the WAR I used is the one distributed at http://basex.org/products/download/all-downloads/ I used Tomcats Application Manager to deploy it. And then I added this to web.xml
   <context-param>
     <param-name>org.basex.restpath</param-name>
<param-value>/opt/tomcat/webapps/BaseX83</param-value>
   </context-param>
    <context-param>
     <param-name>org.basex.repopath</param-name>
<param-value>/opt/tomcat/webapps/BaseX83</param-value>
   </context-param>
Maybe I should try deploying it manually? If not successful, I will look into Jetty or Glasfish. Paul
Quoted text · Christian Grün · 102 lines
> Hm, difficult. If you want, you can provide us with a minimized WAR > file of your webapp, and we could do some more testing. Unfortunately, > Tomcat regularly caused problems in the past; this is why we are > usually working with Jetty or Glassfish in our projects. > > > > On Thu, Oct 15, 2015 at 4:13 PM, Paul Swennenhuis <paul at swennenhuis.nl> wrote: >> Hi Christian, >> >> Thanks for the swift response. >> I tried to place it in the directory of the importing module as well but >> that did not work either. >> >> >> When I run this query: >> >> <dirs> >> <currentDir> >> {file:current-dir()} >> </currentDir> >> <baseDir> >> {file:base-dir()} >> </baseDir> >> <baseUri> >> {static-base-uri()} >> </baseUri> >> <parent> >> {file:parent(static-base-uri())} >> </parent> >> <abs> >> {file:path-to-native("/")} >> </abs> >> <files> >> {file:children(".")} >> </files> >> </dirs> >> >> >> the output is: >> >> <dirs> >> <currentDir>/</currentDir> >> <baseDir>/opt/tomcat/webapps/BaseX83/xq/</baseDir> >> <baseUri>file:/opt/tomcat/webapps/BaseX83/xq/currentDir.xq</baseUri> >> <parent>/opt/tomcat/webapps/BaseX83/xq/</parent> >> <abs>/</abs> >> <files>./lost+found/ ./media/ ./opt/ ./run/ ./library.xq ./home/ ./var/ >> ./dev/ ./boot/ ./sbin/ ./proc/ ./sys/ ./bin/ ./lib/ ./root/ ./vmlinuz ./mnt/ >> ./usr/ ./lib64/ ./initrd.img ./tmp/ ./srv/ ./etc/</files> >> </dirs> >> >> >> As you can see, the children() of the current directory (.) are server root >> entries. >> >> Paul >> >> >>> Hi Paul, >>> >>>> When I import a module in a .xq file, like this: >>>> import module namespace lib="My Library" at "library.xq"; >>>> BaseX gives me a "[XQST0059] Could not retrieve module '/library.xq' " >>>> error. >>> By default, modules should be found if they are located in the >>> directory of the importing module. >>> >>> The URI of your module can be requested via the function >>> static-base-uri(). What does it return in your environment? >>> >>> Christian >>> >>> >>>> Earlier I installed BaseX on a EC2 instance at Amazon, and there I found >>>> that import modules had to be placed in /usr/share/tomcat7 to be found. >>>> But that directory does not exist on this server, and even when I create >>>> it >>>> and place library.xq there it is still not found. >>>> I tried placing library.xq in the RESTPATH directory, in the REPOPATH >>>> directory, in the home directory of BaseX, but all in vain. >>>> I only get it to work when I place library.xq in the root of the server. >>>> And >>>> that is obviously not something I want to do. >>>> Or, alternatively, when I place it in [some directory] and then change >>>> the >>>> import line to >>>> import module namespace lib="My Library" at "[some >>>> directory]/library.xq"; >>>> In other words, when I change the relative path to an absolute one. >>>> But I'd have to do that for all of my XQuery files (a lot!) and, worse, >>>> I'd >>>> have to change it again if I deploy the .xq files on another server. >>>> >>>> So, to summarize: in which directory/directories does BaseX try to locate >>>> import modules? >>>> And what would I have to do to change the default location(s)? >>>> >>>> Thanks in advance. >>>> >>>> Paul >>

⚡Generated with XQuery