Calling static Java function from XQuery
Hi,
I followed the docs and examples on calling Java functions from XQuery, but when I try and add a package to the repository that calls one of my own functions BaseX complains that it can't find the function. I am running BaseX locally and the class I want to call is in my project's classpath. Any ideas as to what I'm doing wrong?
Cheers Gary
Hi Gary,
we are frequently using and embedding Java code in our projects. Do you have a quick example?
Christian
Quoted text · The Trainspotter · 17 lines
On Wed, Oct 31, 2012 at 7:39 PM, The Trainspotter <wys01 at btinternet.com> wrote: > Hi, > > I followed the docs and examples on calling Java functions from XQuery, but > when I try and add a package to the repository that calls one of my own > functions BaseX complains that it can't find the function. I am running > BaseX locally and the class I want to call is in my project's classpath. Any > ideas as to what I'm doing wrong? > > Cheers > Gary > > _______________________________________________ > BaseX-Talk mailing list > BaseX-Talk at mailman.uni-konstanz.de > https://mailman.uni-konstanz.de/mailman/listinfo/basex-talk >
Sure, here's the module I'm trying to load:
module namespace ts="www.tspotter.net";
declare namespace xqc="net.tspotter.sdk.plugin.model.XQueryCalculator";
declare function ts:getEntryFromPrimaryKey( $primaryKey as xs:string )
{
let $expression := xqc:getEntryXPath( $primaryKey )
return xquery:eval( $expression )
};And then in my java class I have:
public class XQueryCalculator
{
public static String getEntryXPath( String id )
{
// do some stuff
return ret;
}
.
.
.
}Is there anything else you need to see?
Cheers Gary
________________________________ From: Christian Grün <christian.gruen at gmail.com> To: The Trainspotter <wys01 at btinternet.com> Cc: "basex-talk at mailman.uni-konstanz.de" <basex-talk at mailman.uni-konstanz.de> Sent: Wednesday, 31 October 2012, 18:41 Subject: Re: [basex-talk] Calling static Java function from XQuery
Hi Gary,
we are frequently using and embedding Java code in our projects. Do you have a quick example?
Christian
Quoted text · The Trainspotter · 17 lines
On Wed, Oct 31, 2012 at 7:39 PM, The Trainspotter <wys01 at btinternet.com> wrote: > Hi, > > I followed the docs and examples on calling Java functions from XQuery, but > when I try and add a package to the repository that calls one of my own > functions BaseX complains that it can't find the function. I am running > BaseX locally and the class I want to call is in my project's classpath. Any > ideas as to what I'm doing wrong? > > Cheers > Gary > > _______________________________________________ > BaseX-Talk mailing list > BaseX-Talk at mailman.uni-konstanz.de > https://mailman.uni-konstanz.de/mailman/listinfo/basex-talk >
Does your code work if you remove the "static" flag from the getEntryXPath function? ___________________________
Christian Grün Box 188, Uni KN D-78457 Konstanz http://christian-gruen.de
Quoted text · The Trainspotter · 69 lines
On Wed, Oct 31, 2012 at 7:52 PM, The Trainspotter <wys01 at btinternet.com> wrote: > Sure, here's the module I'm trying to load: > > module namespace ts="www.tspotter.net"; > declare namespace xqc="net.tspotter.sdk.plugin.model.XQueryCalculator"; > > declare function ts:getEntryFromPrimaryKey( $primaryKey as xs:string ) > { > let $expression := xqc:getEntryXPath( $primaryKey ) > return xquery:eval( $expression ) > }; > > And then in my java class I have: > > public class XQueryCalculator > { > public static String getEntryXPath( String id ) > { > // do some stuff > return ret; > } > . > . > . > } > > Is there anything else you need to see? > > Cheers > Gary > > ________________________________ > From: Christian Grün <christian.gruen at gmail.com> > To: The Trainspotter <wys01 at btinternet.com> > Cc: "basex-talk at mailman.uni-konstanz.de" > <basex-talk at mailman.uni-konstanz.de> > Sent: Wednesday, 31 October 2012, 18:41 > Subject: Re: [basex-talk] Calling static Java function from XQuery > > Hi Gary, > > we are frequently using and embedding Java code in our projects. Do > you have a quick example? > > Christian > ___________________________ > > On Wed, Oct 31, 2012 at 7:39 PM, The Trainspotter <wys01 at btinternet.com> > wrote: >> Hi, >> >> I followed the docs and examples on calling Java functions from XQuery, >> but >> when I try and add a package to the repository that calls one of my own >> functions BaseX complains that it can't find the function. I am running >> BaseX locally and the class I want to call is in my project's classpath. >> Any >> ideas as to what I'm doing wrong? >> >> Cheers >> Gary >> >> _______________________________________________ >> BaseX-Talk mailing list >> BaseX-Talk at mailman.uni-konstanz.de >> https://mailman.uni-konstanz.de/mailman/listinfo/basex-talk >> > >
I tried adding a member function to see if that worked, but it didn't. I've now recoded my Java function in XQuery, but I would still like to get to the bottom of why it's not working as I'm sure I'm going to want to use this feature again soon.
Cheers Gary
________________________________ From: Christian Grün <christian.gruen at gmail.com> To: The Trainspotter <wys01 at btinternet.com> Cc: "basex-talk at mailman.uni-konstanz.de" <basex-talk at mailman.uni-konstanz.de> Sent: Wednesday, 31 October 2012, 18:55 Subject: Re: [basex-talk] Calling static Java function from XQuery
Does your code work if you remove the "static" flag from the getEntryXPath function? ___________________________
Christian Grün Box 188, Uni KN D-78457 Konstanz http://christian-gruen.de
Quoted text · The Trainspotter · 69 lines
On Wed, Oct 31, 2012 at 7:52 PM, The Trainspotter <wys01 at btinternet.com> wrote: > Sure, here's the module I'm trying to load: > > module namespace ts="www.tspotter.net"; > declare namespace xqc="net.tspotter.sdk.plugin.model.XQueryCalculator"; > > declare function ts:getEntryFromPrimaryKey( $primaryKey as xs:string ) > { > let $expression := xqc:getEntryXPath( $primaryKey ) > return xquery:eval( $expression ) > }; > > And then in my java class I have: > > public class XQueryCalculator > { > public static String getEntryXPath( String id ) > { > // do some stuff > return ret; > } > . > . > . > } > > Is there anything else you need to see? > > Cheers > Gary > > ________________________________ > From: Christian Grün <christian.gruen at gmail.com> > To: The Trainspotter <wys01 at btinternet.com> > Cc: "basex-talk at mailman.uni-konstanz.de" > <basex-talk at mailman.uni-konstanz.de> > Sent: Wednesday, 31 October 2012, 18:41 > Subject: Re: [basex-talk] Calling static Java function from XQuery > > Hi Gary, > > we are frequently using and embedding Java code in our projects. Do > you have a quick example? > > Christian > ___________________________ > > On Wed, Oct 31, 2012 at 7:39 PM, The Trainspotter <wys01 at btinternet.com> > wrote: >> Hi, >> >> I followed the docs and examples on calling Java functions from XQuery, >> but >> when I try and add a package to the repository that calls one of my own >> functions BaseX complains that it can't find the function. I am running >> BaseX locally and the class I want to call is in my project's classpath. >> Any >> ideas as to what I'm doing wrong? >> >> Cheers >> Gary >> >> _______________________________________________ >> BaseX-Talk mailing list >> BaseX-Talk at mailman.uni-konstanz.de >> https://mailman.uni-konstanz.de/mailman/listinfo/basex-talk >> > >
I've tried your little example. It works fine on my system, so feel free to send me an sscce, which allows us to reproduce the issue locally.
Best, Christian
___________________________
Christian Grün Box 188, Uni KN D-78457 Konstanz http://christian-gruen.de
Quoted text · The Trainspotter · 100 lines
On Wed, Oct 31, 2012 at 11:47 PM, The Trainspotter <wys01 at btinternet.com> wrote: > I tried adding a member function to see if that worked, but it didn't. I've > now recoded my Java function in XQuery, but I would still like to get to the > bottom of why it's not working as I'm sure I'm going to want to use this > feature again soon. > > Cheers > Gary > > ________________________________ > From: Christian Grün <christian.gruen at gmail.com> > To: The Trainspotter <wys01 at btinternet.com> > Cc: "basex-talk at mailman.uni-konstanz.de" > <basex-talk at mailman.uni-konstanz.de> > Sent: Wednesday, 31 October 2012, 18:55 > > Subject: Re: [basex-talk] Calling static Java function from XQuery > > Does your code work if you remove the "static" flag from the > getEntryXPath function? > ___________________________ > > Christian Grün > Box 188, Uni KN > D-78457 Konstanz > http://christian-gruen.de > > > On Wed, Oct 31, 2012 at 7:52 PM, The Trainspotter <wys01 at btinternet.com> > wrote: >> Sure, here's the module I'm trying to load: >> >> module namespace ts="www.tspotter.net"; >> declare namespace xqc="net.tspotter.sdk.plugin.model.XQueryCalculator"; >> >> declare function ts:getEntryFromPrimaryKey( $primaryKey as xs:string ) >> { >> let $expression := xqc:getEntryXPath( $primaryKey ) >> return xquery:eval( $expression ) >> }; >> >> And then in my java class I have: >> >> public class XQueryCalculator >> { >> public static String getEntryXPath( String id ) >> { >> // do some stuff >> return ret; >> } >> . >> . >> . >> } >> >> Is there anything else you need to see? >> >> Cheers >> Gary >> >> ________________________________ >> From: Christian Grün <christian.gruen at gmail.com> >> To: The Trainspotter <wys01 at btinternet.com> >> Cc: "basex-talk at mailman.uni-konstanz.de" >> <basex-talk at mailman.uni-konstanz.de> >> Sent: Wednesday, 31 October 2012, 18:41 >> Subject: Re: [basex-talk] Calling static Java function from XQuery >> >> Hi Gary, >> >> we are frequently using and embedding Java code in our projects. Do >> you have a quick example? >> >> Christian >> ___________________________ >> >> On Wed, Oct 31, 2012 at 7:39 PM, The Trainspotter <wys01 at btinternet.com> >> wrote: >>> Hi, >>> >>> I followed the docs and examples on calling Java functions from XQuery, >>> but >>> when I try and add a package to the repository that calls one of my own >>> functions BaseX complains that it can't find the function. I am running >>> BaseX locally and the class I want to call is in my project's classpath. >>> Any >>> ideas as to what I'm doing wrong? >>> >>> Cheers >>> Gary >>> >>> _______________________________________________ >>> BaseX-Talk mailing list >>> BaseX-Talk at mailman.uni-konstanz.de >>> https://mailman.uni-konstanz.de/mailman/listinfo/basex-talk >>> >> >> > >
I have a suspicion that it's an issue with how the basex jar file is being loaded - in my project it's being loaded as part of an eclipse plugin and therefore my class won't be on it's classpath.
________________________________ From: Christian Grün <christian.gruen at gmail.com> To: The Trainspotter <wys01 at btinternet.com> Cc: "basex-talk at mailman.uni-konstanz.de" <basex-talk at mailman.uni-konstanz.de> Sent: Wednesday, 31 October 2012, 22:52 Subject: Re: [basex-talk] Calling static Java function from XQuery
I've tried your little example. It works fine on my system, so feel free to send me an sscce, which allows us to reproduce the issue locally.
Best, Christian
___________________________
Christian Grün Box 188, Uni KN D-78457 Konstanz http://christian-gruen.de
Quoted text · The Trainspotter · 100 lines
On Wed, Oct 31, 2012 at 11:47 PM, The Trainspotter <wys01 at btinternet.com> wrote: > I tried adding a member function to see if that worked, but it didn't. I've > now recoded my Java function in XQuery, but I would still like to get to the > bottom of why it's not working as I'm sure I'm going to want to use this > feature again soon. > > Cheers > Gary > > ________________________________ > From: Christian Grün <christian.gruen at gmail.com> > To: The Trainspotter <wys01 at btinternet.com> > Cc: "basex-talk at mailman.uni-konstanz.de" > <basex-talk at mailman.uni-konstanz.de> > Sent: Wednesday, 31 October 2012, 18:55 > > Subject: Re: [basex-talk] Calling static Java function from XQuery > > Does your code work if you remove the "static" flag from the > getEntryXPath function? > ___________________________ > > Christian Grün > Box 188, Uni KN > D-78457 Konstanz > http://christian-gruen.de > > > On Wed, Oct 31, 2012 at 7:52 PM, The Trainspotter <wys01 at btinternet.com> > wrote: >> Sure, here's the module I'm trying to load: >> >> module namespace ts="www.tspotter.net"; >> declare namespace xqc="net.tspotter.sdk.plugin.model.XQueryCalculator"; >> >> declare function ts:getEntryFromPrimaryKey( $primaryKey as xs:string ) >> { >> let $expression := xqc:getEntryXPath( $primaryKey ) >> return xquery:eval( $expression ) >> }; >> >> And then in my java class I have: >> >> public class XQueryCalculator >> { >> public static String getEntryXPath( String id ) >> { >> // do some stuff >> return ret; >> } >> . >> . >> . >> } >> >> Is there anything else you need to see? >> >> Cheers >> Gary >> >> ________________________________ >> From: Christian Grün <christian.gruen at gmail.com> >> To: The Trainspotter <wys01 at btinternet.com> >> Cc: "basex-talk at mailman.uni-konstanz.de" >> <basex-talk at mailman.uni-konstanz.de> >> Sent: Wednesday, 31 October 2012, 18:41 >> Subject: Re: [basex-talk] Calling static Java function from XQuery >> >> Hi Gary, >> >> we are frequently using and embedding Java code in our projects. Do >> you have a quick example? >> >> Christian >> ___________________________ >> >> On Wed, Oct 31, 2012 at 7:39 PM, The Trainspotter <wys01 at btinternet.com> >> wrote: >>> Hi, >>> >>> I followed the docs and examples on calling Java functions from XQuery, >>> but >>> when I try and add a package to the repository that calls one of my own >>> functions BaseX complains that it can't find the function. I am running >>> BaseX locally and the class I want to call is in my project's classpath. >>> Any >>> ideas as to what I'm doing wrong? >>> >>> Cheers >>> Gary >>> >>> _______________________________________________ >>> BaseX-Talk mailing list >>> BaseX-Talk at mailman.uni-konstanz.de >>> https://mailman.uni-konstanz.de/mailman/listinfo/basex-talk >>> >> >> > >
..maybe you could try to get your example running without Eclipse first?
Quoted text · The Trainspotter · 134 lines
On Thu, Nov 1, 2012 at 12:02 AM, The Trainspotter <wys01 at btinternet.com> wrote: > I have a suspicion that it's an issue with how the basex jar file is being > loaded - in my project it's being loaded as part of an eclipse plugin and > therefore my class won't be on it's classpath. > > ________________________________ > From: Christian Grün <christian.gruen at gmail.com> > To: The Trainspotter <wys01 at btinternet.com> > Cc: "basex-talk at mailman.uni-konstanz.de" > <basex-talk at mailman.uni-konstanz.de> > Sent: Wednesday, 31 October 2012, 22:52 > > Subject: Re: [basex-talk] Calling static Java function from XQuery > > I've tried your little example. It works fine on my system, so feel > free to send me an sscce, which allows us to reproduce the issue > locally. > > Best, > Christian > > ___________________________ > > Christian Grün > Box 188, Uni KN > D-78457 Konstanz > http://christian-gruen.de > > > On Wed, Oct 31, 2012 at 11:47 PM, The Trainspotter <wys01 at btinternet.com> > wrote: >> I tried adding a member function to see if that worked, but it didn't. >> I've >> now recoded my Java function in XQuery, but I would still like to get to >> the >> bottom of why it's not working as I'm sure I'm going to want to use this >> feature again soon. >> >> Cheers >> Gary >> >> ________________________________ >> From: Christian Grün <christian.gruen at gmail.com> >> To: The Trainspotter <wys01 at btinternet.com> >> Cc: "basex-talk at mailman.uni-konstanz.de" >> <basex-talk at mailman.uni-konstanz.de> >> Sent: Wednesday, 31 October 2012, 18:55 >> >> Subject: Re: [basex-talk] Calling static Java function from XQuery >> >> Does your code work if you remove the "static" flag from the >> getEntryXPath function? >> ___________________________ >> >> Christian Grün >> Box 188, Uni KN >> D-78457 Konstanz >> http://christian-gruen.de >> >> >> On Wed, Oct 31, 2012 at 7:52 PM, The Trainspotter <wys01 at btinternet.com> >> wrote: >>> Sure, here's the module I'm trying to load: >>> >>> module namespace ts="www.tspotter.net"; >>> declare namespace xqc="net.tspotter.sdk.plugin.model.XQueryCalculator"; >>> >>> declare function ts:getEntryFromPrimaryKey( $primaryKey as xs:string ) >>> { >>> let $expression := xqc:getEntryXPath( $primaryKey ) >>> return xquery:eval( $expression ) >>> }; >>> >>> And then in my java class I have: >>> >>> public class XQueryCalculator >>> { >>> public static String getEntryXPath( String id ) >>> { >>> // do some stuff >>> return ret; >>> } >>> . >>> . >>> . >>> } >>> >>> Is there anything else you need to see? >>> >>> Cheers >>> Gary >>> >>> ________________________________ >>> From: Christian Grün <christian.gruen at gmail.com> >>> To: The Trainspotter <wys01 at btinternet.com> >>> Cc: "basex-talk at mailman.uni-konstanz.de" >>> <basex-talk at mailman.uni-konstanz.de> >>> Sent: Wednesday, 31 October 2012, 18:41 >>> Subject: Re: [basex-talk] Calling static Java function from XQuery >>> >>> Hi Gary, >>> >>> we are frequently using and embedding Java code in our projects. Do >>> you have a quick example? >>> >>> Christian >>> ___________________________ >>> >>> On Wed, Oct 31, 2012 at 7:39 PM, The Trainspotter <wys01 at btinternet.com> >>> wrote: >>>> Hi, >>>> >>>> I followed the docs and examples on calling Java functions from XQuery, >>>> but >>>> when I try and add a package to the repository that calls one of my own >>>> functions BaseX complains that it can't find the function. I am running >>>> BaseX locally and the class I want to call is in my project's classpath. >>>> Any >>>> ideas as to what I'm doing wrong? >>>> >>>> Cheers >>>> Gary >>>> >>>> _______________________________________________ >>>> BaseX-Talk mailing list >>>> BaseX-Talk at mailman.uni-konstanz.de >>>> https://mailman.uni-konstanz.de/mailman/listinfo/basex-talk >>>> >>> >>> >> >> > >
Written for BaseX 7.3. BaseX may have changed since: please check the current documentation.