Java Modules - Constructor

Friday, 5 May 2017 · 11 messages · last reply 15 May 2017
K
kovacic5 May 2017 12:20 #
Hi all, I am running BaseX 8.6.3 currently and struggling with the inclusion of modules written in Java. I have extended the Hello World example: package org.basex.modules;
public class Hello {

     private String str = "BaseX";

     public Hello() {}

     public Hello(String str) {
         this.str = str;
     }

     public String hello(final String world) {
         return "Hello " + world;
     }

     public String hello() {
         return "Hello " + str;
     }
}
I can pack it into a jar-file and install it successfully. My jar-file is structured as following: hello.jar - META-INF - MANIFEST.MF - org - basex - modules - Hello.class Here is the content of my manifest.mf: Manifest-Version: 1.0 Main-Class: org.basex.modules.Hello The methods of the Hello-class can be called without any problems when the module is imported: import module namespace t='org.basex.modules.Hello';
t:hello('text')
However, when I try to explicitly create the object by calling the constructor (new) with arguments it fails:
declare namespace t='org.basex.modules.Hello';

let $obj := t:new('test')
return '' When I try to call the constructor I receive the error [XPST0017] Unknown function: Q{org.basex.modules.Hello}new. Since I am able to execute the FileWriter example (http://docs.basex.org/wiki/Java_Bindings#Namespace_Declarations) which calls a constructor with an argument I would like to know if this behavior is a bug or if I am missing an important point. Regards, Ilko
AB
Andy Bunce5 May 2017 19:29 #
Hi IIko Your code and:
declare namespace t='org.basex.modules.Hello';
let $obj := t:new('works for me')
return t:hello($obj)
Returns: Hello works for me Could be be that you have multiple versions of the jar on the path? Regards /Andy
Quoted text · kovacic · 72 lines
On 5 May 2017 at 11:20, kovacic <kovacic at dke.uni-linz.ac.at> wrote: > Hi all, > > I am running BaseX 8.6.3 currently and struggling with the inclusion of > modules written in Java. I have extended the Hello World example: > > package org.basex.modules; > > public class Hello { > > private String str = "BaseX"; > > public Hello() {} > > public Hello(String str) { > this.str = str; > } > > public String hello(final String world) { > return "Hello " + world; > } > > public String hello() { > return "Hello " + str; > } > } > > I can pack it into a jar-file and install it successfully. My jar-file is > structured as following: > > hello.jar > - META-INF > - MANIFEST.MF > - org > - basex > - modules > - Hello.class > > Here is the content of my manifest.mf: > > Manifest-Version: 1.0 > Main-Class: org.basex.modules.Hello > > The methods of the Hello-class can be called without any problems when the > module is imported: > > import module namespace t='org.basex.modules.Hello'; > > t:hello('text') > > However, when I try to explicitly create the object by calling the > constructor (new) with arguments it fails: > > declare namespace t='org.basex.modules.Hello'; > > let $obj := t:new('test') > > return '' > > When I try to call the constructor I receive the error [XPST0017] Unknown > function: Q{org.basex.modules.Hello}new. > > Since I am able to execute the FileWriter example ( > http://docs.basex.org/wiki/Java_Bindings#Namespace_Declarations) which > calls a constructor with an argument I would like to know if this behavior > is a bug or if I am missing an important point. > > Regards, > Ilko > > >
AB
Andy Bunce8 May 2017 13:43 #
​​Hi Ilko,
Quoted text · Andy Bunce · 1 line
>The repo folder was completely empty.
So you want to install it in the repository, using repo install? My test was installing via copying the jar to basex/lib/ where it works (for me). If I use repo install I get the same problem as you. This may be a bug/feature. It is possible that using the full EXPath Packaging [1] xar would work although I have not tried it. This would involve adding an XQuery file with expath-pkg.xml and basex.xml files to create a xar wrapping the jar, structured as here [2] The issue [3] may be relevant. Regards /Andy ​ hello-test.jar <https://drive.google.com/file/d/0B_HWsgek7hAeTjFnSFg3cGVpMXc/view?usp=drive_web> ​ [1] http://docs.basex.org/wiki/Repository#Java_2 [2] https://github.com/expkg-zone58/metadata-extract/tree/master/src/main [3] https://github.com/BaseXdb/basex/issues/1413
Quoted text · kovacic · 116 lines
On 8 May 2017 at 11:44, kovacic <kovacic at dke.uni-linz.ac.at> wrote: > Hi Andy, > > I have removed all other existing modules before installing this module. > The repo folder was completely empty. > > Regards > Ilko > > Am 05.05.2017 um 19:29 schrieb Andy Bunce: > > Hi IIko > > Your code and: > > declare namespace t='org.basex.modules.Hello'; > let $obj := t:new('works for me') > return t:hello($obj) > > Returns: > > Hello works for me > > Could be be that you have multiple versions of the jar on the path? > > Regards > /Andy > > On 5 May 2017 at 11:20, kovacic <kovacic at dke.uni-linz.ac.at> wrote: > >> Hi all, >> >> I am running BaseX 8.6.3 currently and struggling with the inclusion of >> modules written in Java. I have extended the Hello World example: >> >> package org.basex.modules; >> >> public class Hello { >> >> private String str = "BaseX"; >> >> public Hello() {} >> >> public Hello(String str) { >> this.str = str; >> } >> >> public String hello(final String world) { >> return "Hello " + world; >> } >> >> public String hello() { >> return "Hello " + str; >> } >> } >> >> I can pack it into a jar-file and install it successfully. My jar-file is >> structured as following: >> >> hello.jar >> - META-INF >> - MANIFEST.MF >> - org >> - basex >> - modules >> - Hello.class >> >> Here is the content of my manifest.mf: >> >> Manifest-Version: 1.0 >> Main-Class: org.basex.modules.Hello >> >> The methods of the Hello-class can be called without any problems when >> the module is imported: >> >> import module namespace t='org.basex.modules.Hello'; >> >> t:hello('text') >> >> However, when I try to explicitly create the object by calling the >> constructor (new) with arguments it fails: >> >> declare namespace t='org.basex.modules.Hello'; >> >> let $obj := t:new('test') >> >> return '' >> >> When I try to call the constructor I receive the error [XPST0017] Unknown >> function: Q{org.basex.modules.Hello}new. >> >> Since I am able to execute the FileWriter example ( >> http://docs.basex.org/wiki/Java_Bindings#Namespace_Declarations) which >> calls a constructor with an argument I would like to know if this behavior >> is a bug or if I am missing an important point. >> >> Regards, >> Ilko >> >> >> > > -- > *Ilko Kovacic* > Wissenschaftlicher Mitarbeiter > Institut für Wirtschaftsinformatik - Data & Knowledge Engineering > > > *JOHANNES KEPLER UNIVERSITÄT LINZ* > Altenberger Straße 69 > Science Park III, S3 111 > 4040 Linz, Österreich > T +43 732 2468 4286 <+43%20732%2024684286> > ilko.kovacic at jku.at > www.dke.jku.at >
AB
Andy Bunce8 May 2017 15:00 #
Great. I believe the windows exe has a hard coded class path so ignores any additions. /Andy
Quoted text · kovacic · 213 lines
On 8 May 2017 at 13:24, kovacic <kovacic at dke.uni-linz.ac.at> wrote: > Thank you Andy. It works by starting the GUI using the basexgui.bat. > > Regards > Ilko > > Am 08.05.2017 um 14:21 schrieb Andy Bunce: > > > 1. download + unzip http://files.basex.org/releases/8.6.3/BaseX863.zip > 2. copy hello-test.jar to lib/ > 3. run bin/basexgui.bat > 4. execute: > > declare namespace t='org.basex.modules.Hello'; > let $obj := t:new('works for me') > return t:hello($obj) > > Regards > /Andy > > On 8 May 2017 at 13:16, kovacic <kovacic at dke.uni-linz.ac.at> wrote: > >> Hi Andy, >> >> I followed the instructions from here http://docs.basex.org/wiki/Rep >> ository#Java. >> >> I copied the jar to the basex/lib/ folder but it still does not work. >> Which version of BaseX are you using? >> >> Regards >> Ilko >> >> Am 08.05.2017 um 13:43 schrieb Andy Bunce: >> >> ​​Hi Ilko, >> >> >The repo folder was completely empty. >> So you want to install it in the repository, using repo install? >> >> My test was installing via copying the jar to basex/lib/ where it works >> (for me). >> If I use repo install I get the same problem as you. >> >> This may be a bug/feature. >> It is possible that using the full EXPath Packaging [1] xar would work >> although I have not tried it. >> This would involve adding an XQuery file with expath-pkg.xml and >> basex.xml files to create a xar wrapping the jar, structured as here [2] >> The issue [3] may be relevant. >> >> Regards >> /Andy >> ​ >> hello-test.jar >> <https://drive.google.com/file/d/0B_HWsgek7hAeTjFnSFg3cGVpMXc/view?usp=drive_web> >> ​ >> [1] http://docs.basex.org/wiki/Repository#Java_2 >> [2] https://github.com/expkg-zone58/metadata-extract/tree/master/src/main >> [3] https://github.com/BaseXdb/basex/issues/1413 >> >> >> >> On 8 May 2017 at 11:44, kovacic <kovacic at dke.uni-linz.ac.at> wrote: >> >>> Hi Andy, >>> >>> I have removed all other existing modules before installing this module. >>> The repo folder was completely empty. >>> >>> Regards >>> Ilko >>> >>> Am 05.05.2017 um 19:29 schrieb Andy Bunce: >>> >>> Hi IIko >>> >>> Your code and: >>> >>> declare namespace t='org.basex.modules.Hello'; >>> let $obj := t:new('works for me') >>> return t:hello($obj) >>> >>> Returns: >>> >>> Hello works for me >>> >>> Could be be that you have multiple versions of the jar on the path? >>> >>> Regards >>> /Andy >>> >>> On 5 May 2017 at 11:20, kovacic <kovacic at dke.uni-linz.ac.at> wrote: >>> >>>> Hi all, >>>> >>>> I am running BaseX 8.6.3 currently and struggling with the inclusion of >>>> modules written in Java. I have extended the Hello World example: >>>> >>>> package org.basex.modules; >>>> >>>> public class Hello { >>>> >>>> private String str = "BaseX"; >>>> >>>> public Hello() {} >>>> >>>> public Hello(String str) { >>>> this.str = str; >>>> } >>>> >>>> public String hello(final String world) { >>>> return "Hello " + world; >>>> } >>>> >>>> public String hello() { >>>> return "Hello " + str; >>>> } >>>> } >>>> >>>> I can pack it into a jar-file and install it successfully. My jar-file >>>> is structured as following: >>>> >>>> hello.jar >>>> - META-INF >>>> - MANIFEST.MF >>>> - org >>>> - basex >>>> - modules >>>> - Hello.class >>>> >>>> Here is the content of my manifest.mf: >>>> >>>> Manifest-Version: 1.0 >>>> Main-Class: org.basex.modules.Hello >>>> >>>> The methods of the Hello-class can be called without any problems when >>>> the module is imported: >>>> >>>> import module namespace t='org.basex.modules.Hello'; >>>> >>>> t:hello('text') >>>> >>>> However, when I try to explicitly create the object by calling the >>>> constructor (new) with arguments it fails: >>>> >>>> declare namespace t='org.basex.modules.Hello'; >>>> >>>> let $obj := t:new('test') >>>> >>>> return '' >>>> >>>> When I try to call the constructor I receive the error [XPST0017] >>>> Unknown function: Q{org.basex.modules.Hello}new. >>>> >>>> Since I am able to execute the FileWriter example ( >>>> http://docs.basex.org/wiki/Java_Bindings#Namespace_Declarations) which >>>> calls a constructor with an argument I would like to know if this behavior >>>> is a bug or if I am missing an important point. >>>> >>>> Regards, >>>> Ilko >>>> >>>> >>>> >>> >>> -- >>> *Ilko Kovacic* >>> Wissenschaftlicher Mitarbeiter >>> Institut für Wirtschaftsinformatik - Data & Knowledge Engineering >>> >>> >>> *JOHANNES KEPLER UNIVERSITÄT LINZ* >>> Altenberger Straße 69 >>> Science Park III, S3 111 >>> 4040 Linz, Österreich >>> T +43 732 2468 4286 <+43%20732%2024684286> >>> ilko.kovacic at jku.at >>> www.dke.jku.at >>> >> >> >> -- >> *Ilko Kovacic* >> Wissenschaftlicher Mitarbeiter >> Institut für Wirtschaftsinformatik - Data & Knowledge Engineering >> >> >> *JOHANNES KEPLER UNIVERSITÄT LINZ* >> Altenberger Straße 69 >> Science Park III, S3 111 >> 4040 Linz, Österreich >> T +43 732 2468 4286 <+43%20732%2024684286> >> ilko.kovacic at jku.at >> www.dke.jku.at >> > > > -- > *Ilko Kovacic* > Wissenschaftlicher Mitarbeiter > Institut für Wirtschaftsinformatik - Data & Knowledge Engineering > > > *JOHANNES KEPLER UNIVERSITÄT LINZ* > Altenberger Straße 69 > Science Park III, S3 111 > 4040 Linz, Österreich > T +43 732 2468 4286 <+43%20732%2024684286> > ilko.kovacic at jku.at > www.dke.jku.at >
CG
Christian Grün11 May 2017 20:13 #
Hi Andy,
Quoted text · Andy Bunce · 3 lines
Great. I believe the windows exe has a hard coded class path so ignores any > additions. >
​Oh yes, that’s true. There have been several versions of BaseX.exe in the past, all with specific advantages and drawbacks. We may need to rethink the way how we build the Windows executable. Thanks for the reminder, Christian
Quoted text · Andy Bunce · 219 lines
> /Andy > > On 8 May 2017 at 13:24, kovacic <kovacic at dke.uni-linz.ac.at> wrote: > >> Thank you Andy. It works by starting the GUI using the basexgui.bat. >> >> Regards >> Ilko >> >> Am 08.05.2017 um 14:21 schrieb Andy Bunce: >> >> >> 1. download + unzip http://files.basex.org/releases/8.6.3/BaseX863.zip >> 2. copy hello-test.jar to lib/ >> 3. run bin/basexgui.bat >> 4. execute: >> >> declare namespace t='org.basex.modules.Hello'; >> let $obj := t:new('works for me') >> return t:hello($obj) >> >> Regards >> /Andy >> >> On 8 May 2017 at 13:16, kovacic <kovacic at dke.uni-linz.ac.at> wrote: >> >>> Hi Andy, >>> >>> I followed the instructions from here http://docs.basex.org/wiki/Rep >>> ository#Java. >>> >>> I copied the jar to the basex/lib/ folder but it still does not work. >>> Which version of BaseX are you using? >>> >>> Regards >>> Ilko >>> >>> Am 08.05.2017 um 13:43 schrieb Andy Bunce: >>> >>> ​​Hi Ilko, >>> >>> >The repo folder was completely empty. >>> So you want to install it in the repository, using repo install? >>> >>> My test was installing via copying the jar to basex/lib/ where it works >>> (for me). >>> If I use repo install I get the same problem as you. >>> >>> This may be a bug/feature. >>> It is possible that using the full EXPath Packaging [1] xar would work >>> although I have not tried it. >>> This would involve adding an XQuery file with expath-pkg.xml and >>> basex.xml files to create a xar wrapping the jar, structured as here [2] >>> The issue [3] may be relevant. >>> >>> Regards >>> /Andy >>> ​ >>> hello-test.jar >>> <https://drive.google.com/file/d/0B_HWsgek7hAeTjFnSFg3cGVpMXc/view?usp=drive_web> >>> ​ >>> [1] http://docs.basex.org/wiki/Repository#Java_2 >>> [2] https://github.com/expkg-zone58/metadata-extract/tree/master >>> /src/main >>> [3] https://github.com/BaseXdb/basex/issues/1413 >>> >>> >>> >>> On 8 May 2017 at 11:44, kovacic <kovacic at dke.uni-linz.ac.at> wrote: >>> >>>> Hi Andy, >>>> >>>> I have removed all other existing modules before installing this >>>> module. The repo folder was completely empty. >>>> >>>> Regards >>>> Ilko >>>> >>>> Am 05.05.2017 um 19:29 schrieb Andy Bunce: >>>> >>>> Hi IIko >>>> >>>> Your code and: >>>> >>>> declare namespace t='org.basex.modules.Hello'; >>>> let $obj := t:new('works for me') >>>> return t:hello($obj) >>>> >>>> Returns: >>>> >>>> Hello works for me >>>> >>>> Could be be that you have multiple versions of the jar on the path? >>>> >>>> Regards >>>> /Andy >>>> >>>> On 5 May 2017 at 11:20, kovacic <kovacic at dke.uni-linz.ac.at> wrote: >>>> >>>>> Hi all, >>>>> >>>>> I am running BaseX 8.6.3 currently and struggling with the inclusion >>>>> of modules written in Java. I have extended the Hello World example: >>>>> >>>>> package org.basex.modules; >>>>> >>>>> public class Hello { >>>>> >>>>> private String str = "BaseX"; >>>>> >>>>> public Hello() {} >>>>> >>>>> public Hello(String str) { >>>>> this.str = str; >>>>> } >>>>> >>>>> public String hello(final String world) { >>>>> return "Hello " + world; >>>>> } >>>>> >>>>> public String hello() { >>>>> return "Hello " + str; >>>>> } >>>>> } >>>>> >>>>> I can pack it into a jar-file and install it successfully. My jar-file >>>>> is structured as following: >>>>> >>>>> hello.jar >>>>> - META-INF >>>>> - MANIFEST.MF >>>>> - org >>>>> - basex >>>>> - modules >>>>> - Hello.class >>>>> >>>>> Here is the content of my manifest.mf: >>>>> >>>>> Manifest-Version: 1.0 >>>>> Main-Class: org.basex.modules.Hello >>>>> >>>>> The methods of the Hello-class can be called without any problems when >>>>> the module is imported: >>>>> >>>>> import module namespace t='org.basex.modules.Hello'; >>>>> >>>>> t:hello('text') >>>>> >>>>> However, when I try to explicitly create the object by calling the >>>>> constructor (new) with arguments it fails: >>>>> >>>>> declare namespace t='org.basex.modules.Hello'; >>>>> >>>>> let $obj := t:new('test') >>>>> >>>>> return '' >>>>> >>>>> When I try to call the constructor I receive the error [XPST0017] >>>>> Unknown function: Q{org.basex.modules.Hello}new. >>>>> >>>>> Since I am able to execute the FileWriter example ( >>>>> http://docs.basex.org/wiki/Java_Bindings#Namespace_Declarations) >>>>> which calls a constructor with an argument I would like to know if this >>>>> behavior is a bug or if I am missing an important point. >>>>> >>>>> Regards, >>>>> Ilko >>>>> >>>>> >>>>> >>>> >>>> -- >>>> *Ilko Kovacic* >>>> Wissenschaftlicher Mitarbeiter >>>> Institut für Wirtschaftsinformatik - Data & Knowledge Engineering >>>> >>>> >>>> *JOHANNES KEPLER UNIVERSITÄT LINZ* >>>> Altenberger Straße 69 >>>> Science Park III, S3 111 >>>> 4040 Linz, Österreich >>>> T +43 732 2468 4286 <+43%20732%2024684286> >>>> ilko.kovacic at jku.at >>>> www.dke.jku.at >>>> >>> >>> >>> -- >>> *Ilko Kovacic* >>> Wissenschaftlicher Mitarbeiter >>> Institut für Wirtschaftsinformatik - Data & Knowledge Engineering >>> >>> >>> *JOHANNES KEPLER UNIVERSITÄT LINZ* >>> Altenberger Straße 69 >>> Science Park III, S3 111 >>> 4040 Linz, Österreich >>> T +43 732 2468 4286 <+43%20732%2024684286> >>> ilko.kovacic at jku.at >>> www.dke.jku.at >>> >> >> >> -- >> *Ilko Kovacic* >> Wissenschaftlicher Mitarbeiter >> Institut für Wirtschaftsinformatik - Data & Knowledge Engineering >> >> >> *JOHANNES KEPLER UNIVERSITÄT LINZ* >> Altenberger Straße 69 >> Science Park III, S3 111 >> 4040 Linz, Österreich >> T +43 732 2468 4286 <+43%20732%2024684286> >> ilko.kovacic at jku.at >> www.dke.jku.at >> > >
AB
Andy Bunce11 May 2017 22:06 #
Hi Christian, It would be nice if the exe could pick up added jars but I have got so used to the behavior that I always use basexgui.bat now. In fact I have modified the bat to add a "lib2" folder where I can easier manage extension jars. set CP=%MAIN%/BaseX.jar;%MAIN%/lib/*;%MAIN%/lib2/* But is the original problem a bug? That is after installing the jar via REPO install t:new("aaa") fails although it works when added to lib/ /Andy ​ hello-test.jar <https://drive.google.com/file/d/0B_HWsgek7hAeODk3cjhVd3BpTG8/view?usp=drive_web> ​
Quoted text · Christian Grün · 240 lines
On 11 May 2017 at 19:13, Christian Grün <christian.gruen at gmail.com> wrote: > Hi Andy, > > Great. I believe the windows exe has a hard coded class path so ignores >> any additions. >> > > ​Oh yes, that’s true. There have been several versions of BaseX.exe in the > past, all with specific advantages and drawbacks. We may need to rethink > the way how we build the Windows executable. > > Thanks for the reminder, > Christian > > > > > > >> /Andy >> >> On 8 May 2017 at 13:24, kovacic <kovacic at dke.uni-linz.ac.at> wrote: >> >>> Thank you Andy. It works by starting the GUI using the basexgui.bat. >>> >>> Regards >>> Ilko >>> >>> Am 08.05.2017 um 14:21 schrieb Andy Bunce: >>> >>> >>> 1. download + unzip http://files.basex.org/release >>> s/8.6.3/BaseX863.zip >>> 2. copy hello-test.jar to lib/ >>> 3. run bin/basexgui.bat >>> 4. execute: >>> >>> declare namespace t='org.basex.modules.Hello'; >>> let $obj := t:new('works for me') >>> return t:hello($obj) >>> >>> Regards >>> /Andy >>> >>> On 8 May 2017 at 13:16, kovacic <kovacic at dke.uni-linz.ac.at> wrote: >>> >>>> Hi Andy, >>>> >>>> I followed the instructions from here http://docs.basex.org/wiki/Rep >>>> ository#Java. >>>> >>>> I copied the jar to the basex/lib/ folder but it still does not work. >>>> Which version of BaseX are you using? >>>> >>>> Regards >>>> Ilko >>>> >>>> Am 08.05.2017 um 13:43 schrieb Andy Bunce: >>>> >>>> ​​Hi Ilko, >>>> >>>> >The repo folder was completely empty. >>>> So you want to install it in the repository, using repo install? >>>> >>>> My test was installing via copying the jar to basex/lib/ where it works >>>> (for me). >>>> If I use repo install I get the same problem as you. >>>> >>>> This may be a bug/feature. >>>> It is possible that using the full EXPath Packaging [1] xar would work >>>> although I have not tried it. >>>> This would involve adding an XQuery file with expath-pkg.xml and >>>> basex.xml files to create a xar wrapping the jar, structured as here [2] >>>> The issue [3] may be relevant. >>>> >>>> Regards >>>> /Andy >>>> ​ >>>> hello-test.jar >>>> <https://drive.google.com/file/d/0B_HWsgek7hAeTjFnSFg3cGVpMXc/view?usp=drive_web> >>>> ​ >>>> [1] http://docs.basex.org/wiki/Repository#Java_2 >>>> [2] https://github.com/expkg-zone58/metadata-extract/tree/master >>>> /src/main >>>> [3] https://github.com/BaseXdb/basex/issues/1413 >>>> >>>> >>>> >>>> On 8 May 2017 at 11:44, kovacic <kovacic at dke.uni-linz.ac.at> wrote: >>>> >>>>> Hi Andy, >>>>> >>>>> I have removed all other existing modules before installing this >>>>> module. The repo folder was completely empty. >>>>> >>>>> Regards >>>>> Ilko >>>>> >>>>> Am 05.05.2017 um 19:29 schrieb Andy Bunce: >>>>> >>>>> Hi IIko >>>>> >>>>> Your code and: >>>>> >>>>> declare namespace t='org.basex.modules.Hello'; >>>>> let $obj := t:new('works for me') >>>>> return t:hello($obj) >>>>> >>>>> Returns: >>>>> >>>>> Hello works for me >>>>> >>>>> Could be be that you have multiple versions of the jar on the path? >>>>> >>>>> Regards >>>>> /Andy >>>>> >>>>> On 5 May 2017 at 11:20, kovacic <kovacic at dke.uni-linz.ac.at> wrote: >>>>> >>>>>> Hi all, >>>>>> >>>>>> I am running BaseX 8.6.3 currently and struggling with the inclusion >>>>>> of modules written in Java. I have extended the Hello World example: >>>>>> >>>>>> package org.basex.modules; >>>>>> >>>>>> public class Hello { >>>>>> >>>>>> private String str = "BaseX"; >>>>>> >>>>>> public Hello() {} >>>>>> >>>>>> public Hello(String str) { >>>>>> this.str = str; >>>>>> } >>>>>> >>>>>> public String hello(final String world) { >>>>>> return "Hello " + world; >>>>>> } >>>>>> >>>>>> public String hello() { >>>>>> return "Hello " + str; >>>>>> } >>>>>> } >>>>>> >>>>>> I can pack it into a jar-file and install it successfully. My >>>>>> jar-file is structured as following: >>>>>> >>>>>> hello.jar >>>>>> - META-INF >>>>>> - MANIFEST.MF >>>>>> - org >>>>>> - basex >>>>>> - modules >>>>>> - Hello.class >>>>>> >>>>>> Here is the content of my manifest.mf: >>>>>> >>>>>> Manifest-Version: 1.0 >>>>>> Main-Class: org.basex.modules.Hello >>>>>> >>>>>> The methods of the Hello-class can be called without any problems >>>>>> when the module is imported: >>>>>> >>>>>> import module namespace t='org.basex.modules.Hello'; >>>>>> >>>>>> t:hello('text') >>>>>> >>>>>> However, when I try to explicitly create the object by calling the >>>>>> constructor (new) with arguments it fails: >>>>>> >>>>>> declare namespace t='org.basex.modules.Hello'; >>>>>> >>>>>> let $obj := t:new('test') >>>>>> >>>>>> return '' >>>>>> >>>>>> When I try to call the constructor I receive the error [XPST0017] >>>>>> Unknown function: Q{org.basex.modules.Hello}new. >>>>>> >>>>>> Since I am able to execute the FileWriter example ( >>>>>> http://docs.basex.org/wiki/Java_Bindings#Namespace_Declarations) >>>>>> which calls a constructor with an argument I would like to know if this >>>>>> behavior is a bug or if I am missing an important point. >>>>>> >>>>>> Regards, >>>>>> Ilko >>>>>> >>>>>> >>>>>> >>>>> >>>>> -- >>>>> *Ilko Kovacic* >>>>> Wissenschaftlicher Mitarbeiter >>>>> Institut für Wirtschaftsinformatik - Data & Knowledge Engineering >>>>> >>>>> >>>>> *JOHANNES KEPLER UNIVERSITÄT LINZ* >>>>> Altenberger Straße 69 >>>>> Science Park III, S3 111 >>>>> 4040 Linz, Österreich >>>>> T +43 732 2468 4286 <+43%20732%2024684286> >>>>> ilko.kovacic at jku.at >>>>> www.dke.jku.at >>>>> >>>> >>>> >>>> -- >>>> *Ilko Kovacic* >>>> Wissenschaftlicher Mitarbeiter >>>> Institut für Wirtschaftsinformatik - Data & Knowledge Engineering >>>> >>>> >>>> *JOHANNES KEPLER UNIVERSITÄT LINZ* >>>> Altenberger Straße 69 >>>> Science Park III, S3 111 >>>> 4040 Linz, Österreich >>>> T +43 732 2468 4286 <+43%20732%2024684286> >>>> ilko.kovacic at jku.at >>>> www.dke.jku.at >>>> >>> >>> >>> -- >>> *Ilko Kovacic* >>> Wissenschaftlicher Mitarbeiter >>> Institut für Wirtschaftsinformatik - Data & Knowledge Engineering >>> >>> >>> *JOHANNES KEPLER UNIVERSITÄT LINZ* >>> Altenberger Straße 69 >>> Science Park III, S3 111 >>> 4040 Linz, Österreich >>> T +43 732 2468 4286 <+43%20732%2024684286> >>> ilko.kovacic at jku.at >>> www.dke.jku.at >>> >> >> >
CG
Christian Grün11 May 2017 22:09 #
Quoted text · Andy Bunce · 3 lines
> In fact I have modified the bat to add a "lib2" folder where I can easier manage extension jars. > > set CP=%MAIN%/BaseX.jar;%MAIN%/lib/*;%MAIN%/lib2/*
Good point. For the Windows executable, I thought about adding a 'custom' sub-directory in the lib folder. The jars in the lib directory could be deleted with each update, but the custom folder would be preserved.
Quoted text · Andy Bunce · 2 lines
> But is the original problem a bug? > That is after installing the jar via REPO install t:new("aaa") fails although it works when added to lib/
Be sure I’ll check this out later this week.
LV
Lizzi, Vincent12 May 2017 00:51 #
I like the idea of having a “custom” lib folder, also for the .zip distribution. That would make updating to new versions of BaseX a little easier. Sent from my Windows 10 phone
Quoted text · Christian Grün · 15 lines
From: Christian Grün<mailto:christian.gruen at gmail.com> Sent: Thursday, May 11, 2017 4:09 PM To: Andy Bunce<mailto:bunce.andy at gmail.com> Cc: basex-talk at mailman.uni-konstanz.de<mailto:basex-talk at mailman.uni-konstanz.de> Subject: Re: [basex-talk] Java Modules - Constructor > In fact I have modified the bat to add a "lib2" folder where I can easier manage extension jars. > > set CP=%MAIN%/BaseX.jar;%MAIN%/lib/*;%MAIN%/lib2/* Good point. For the Windows executable, I thought about adding a 'custom' sub-directory in the lib folder. The jars in the lib directory could be deleted with each update, but the custom folder would be preserved. > But is the original problem a bug? > That is after installing the jar via REPO install t:new("aaa") fails although it works when added to lib/ Be sure I’ll check this out later this week.
CG
Christian Grün15 May 2017 10:10 #
Hi Vincent, hi Andy, I’ve created a GitHub issue for this [1]. Best, Christian [1] https://github.com/BaseXdb/basex/issues/1456
Quoted text · Vincent · 36 lines
On Fri, May 12, 2017 at 12:51 AM, Lizzi, Vincent <Vincent.Lizzi at taylorandfrancis.com> wrote: > I like the idea of having a “custom” lib folder, also for the .zip > distribution. That would make updating to new versions of BaseX a little > easier. > > > > Sent from my Windows 10 phone > > > > From: Christian Grün > Sent: Thursday, May 11, 2017 4:09 PM > To: Andy Bunce > Cc: basex-talk at mailman.uni-konstanz.de > Subject: Re: [basex-talk] Java Modules - Constructor > > > >> In fact I have modified the bat to add a "lib2" folder where I can easier >> manage extension jars. >> >> set CP=%MAIN%/BaseX.jar;%MAIN%/lib/*;%MAIN%/lib2/* > > Good point. For the Windows executable, I thought about adding a > 'custom' sub-directory in the lib folder. The jars in the lib > directory could be deleted with each update, but the custom folder > would be preserved. > >> But is the original problem a bug? >> That is after installing the jar via REPO install t:new("aaa") fails >> although it works when added to lib/ > > Be sure I’ll check this out later this week. >
CG
Christian Grünin reply to Andy Bunce, 11 May 2017, 22:0615 May 2017 10:15 #
Quoted text · Andy Bunce · 5 lines
> > But is the original problem a bug? > That is after installing the jar via REPO install t:new("aaa") fails > although it works when added to lib/ >
​It’s not really bug, rather a restriction of repository modules (calling it a “feature” may be a bit too euphemistic ;): Repository modules must be imported, and they must have one constructor without arguments.
AB
Andy Bunce15 May 2017 11:55 #
Yes makes sense. If one really wants side effects in a Java Repo module the below will do it. Looking forward to the custom lib feature and lib/custom seems a good name to me. Thanks /Andy --------------------- package org.basex.modules;
public class Hello {

    private String str = "BaseX";

    public Hello() {}

    public void setDefault(String str) {
        this.str = str;
    }

    public String hello(final String world) {
        return "Hello " + world;
    }

    public String hello() {
        return "Hello " + str;
    }
}
-------------------------------
import module namespace t='org.basex.modules.Hello';
t:setDefault("my default"),
t:hello()
Quoted text · Christian Grün · 12 lines
On 15 May 2017 at 09:15, Christian Grün <christian.gruen at gmail.com> wrote: > But is the original problem a bug? >> That is after installing the jar via REPO install t:new("aaa") fails >> although it works when added to lib/ >> > > ​It’s not really bug, rather a restriction of repository modules (calling > it a “feature” may be a bit too euphemistic ;): Repository modules must be > imported, and they must have one constructor without arguments. > > >

⚡Generated with XQuery