The Saxon command line interfaces typically do a System.exit(2) if a query/transformation fails with a dynamic error; this is so that shell scripts can detect whether or not the command was successful. There is no System.exit() call if execution succeeds.

I don't think anyone is especially at fault here. You're using an interface that's designed to be called from a shell script from within a Java application, which is best avoided, but Ant doesn't give you very much alternative. If you really want to make the effort, the right answer is probably to write a different wrapper around the Query API, similar to net.sf.saxon.Query, but with a different strategy for reporting success or failure to the calling application. Alternatively, write the query to be more robust, so it doesn't fail with dynamic errors: I don't think there should be a problem for successful queries.

Another alternative: perhaps you should be using XProc?

Michael Kay

On 08/03/2012 12:09, Tom Cleghorn wrote:

I've got an Ant build in which I use the "java" task to pull a couple of values from an XML document and store them in properties for use later in the build.

Currently, the tasks look like this:

<java classname="net.sf.saxon.Query" outputproperty="oc-isbn" fork="true">
    <pathelement location="${basedir}/lib/saxon9.jar"/>
  <arg value="-qs:doc('${xml-meta}')//book[HB_ISBN='${isbn}']/OC_EAN[1] | doc('${xml-meta}')//book[PB_ISBN='${isbn}']/OC_EAN[1]"/>
  <arg value="!method=text"/>

...and this works. However, I have other builds where setting the result of an Xquery to a property would also be useful, but where I have quite a few more properties to set. So, what I'd really like to do is be able to use 'fork="false"', so that I don't have to wait for a new VM to start up for each property, but this does not work. If I do this, I get "Java Result: 2" from Ant, and the properties remain unset.

I played around a bit, and found that Saxon was complaining about Java security permissions, and that led to finding that, if I specifically granted Saxon all permissions, it would run without error, but then end the build prematurely - with some further fiddling, I found that granting Saxon all permissions *except* ExitVM would give me Java Result: 2 again. So it looks as if Saxon really wants to close the VM when it finishes, but with fork=false, this is the VM in which Ant is running - is this the right conclusion? I'm using Ant 1.8.1, Saxon-B 9.1 and Java 1.6, but I've also tried with Ant 1.7.0, 1.7.1 and 1.8.1, and Saxon HE 9.3 and 9.4.

I'm really running up against the boundaries of my understanding of Java here, so I'm honestly unsure if I'm doing something daft, and even if I'm not, whether it's Saxon, Ant, or Java itself that's causing the problem. Can anyone shed any light?

Many thanks!

Virtualization & Cloud Management Using Capacity Planning
Cloud computing makes use of virtualization - but cloud computing 
also focuses on allowing computing to be delivered as a service.

saxon-help mailing list archived at