Discussion:
Command line arguments with <java> task.
c***@onebox.com
2006-08-08 15:06:22 UTC
Permalink
Last week I had a problem when installing ANT, a build file, and some supporting files on three computers at my workplace. On two of the three computers I was not able to force the <xslt> task to use the XSLT transformer I choose. At least that appeared to be the problem because the error messages sent to the console suggested that the XSLT processor being used didn't understand some XSLT 2.0 functions in the stylesheet.

So far that problem is still unresolved. Since a serious approach to troubleshooting the problem would require that I have exclusive access to the workstations in question for an extended period, thus denying the regular users the opportunity to carry out their normal work.


I got heavily involved in another task, but now I'm back to finding a "Plan B" for this matter. It occurred to me that I could use the <java> task and call the XSLT processor directly. So I looked at the ANT manual concerning the <java> task where I found this:

Examples
<arg value="-l -a"/>

is a single command-line argument containing a space character.

<arg line="-l -a"/>

represents two separate command-line arguments.

To my eye, these appear to be indentical. Which one is wrong?

The test case <java> task in my build file looks like this:

<target name="gen-properties" depends="init">
<java classname="net.sf.saxon.Transform" fork="true">
<classpath>
<pathelement location="${env.SAXON_HOME}/saxon8.jar" />
</classpath>
<arg value="-o ${env.SARS_REPORTS_HOME}\lib\temp\pbd.xml" />
<arg value="${env.SARS_REPORTS_HOME}/lib/federal-holidays.xml" />
<arg value="${env.SARS_REPORTS_HOME}/lib/previous-bus-day.xslt" />
<arg value="dow=${day.of.week}" />
<arg value="span=${span}" />
<arg value="current-date=${current.date}" />
</java>
</target>

The problem I'm now having involves the first <arg> element. When I run the transformer from the command line, passing in the same values for the arguments as shown above, the transformation works as expected. Of course I susbstitute literal strings for the ANT properties in the last three arguments.

When I run the target above instead, I get an error message from the Java class via ANT:
[java] Unknown option -o h:\sars-reports\lib\temp\pbd.xml

If I omit the first <arg> element, the task executes successfully, outputting the transformation to the console window.

I suspect it has something to do with the warning in the ANT manual that I quoted earlier, but as you can see, I find that section of the manual to be incomprehensible.

Please help if you can. Thanks.
--
Charles Knell
***@onebox.com - email
Dominique Devienne
2006-08-08 15:16:56 UTC
Permalink
Post by c***@onebox.com
So far that problem is still unresolved.
Have you tried using -lib saxon.jar on the command line? This puts
saxon first on the classpath, which makes Trax load it instead of the
default JDK-provided XSLT engone.
Post by c***@onebox.com
<arg value="-l -a"/>
<arg line="-l -a"/>
To my eye, these appear to be indentical. Which one is wrong?
the 'value' one is wrong. "-l -a" is not an argument. "-l" and "-a" are.
Post by c***@onebox.com
<target name="gen-properties" depends="init">
<java classname="net.sf.saxon.Transform" fork="true">
<classpath>
<pathelement location="${env.SAXON_HOME}/saxon8.jar" />
</classpath>
<arg value="-o ${env.SARS_REPORTS_HOME}\lib\temp\pbd.xml" />
Use 'line' instead. Better yet, using

<arg value="-o" />
<arg file="${env.SARS_REPORTS_HOME}/lib/temp/pbd.xml" />

Notice the forward-slash. 'value' and 'line' are string-based args,
that don't assume anything about the args. 'file' knows it's a
filename, and "does the right thing" (TM) to convert into a proper
filename for the current platform.
Post by c***@onebox.com
<arg value="${env.SARS_REPORTS_HOME}/lib/federal-holidays.xml" />
<arg value="${env.SARS_REPORTS_HOME}/lib/previous-bus-day.xslt" />
Again, better to use 'file' above.
Post by c***@onebox.com
<arg value="dow=${day.of.week}" />
<arg value="span=${span}" />
<arg value="current-date=${current.date}" />
This is correct OTOH. Even if span (or the other properties) contain
spaces, you most likely want to pass it in as a single argument.
Post by c***@onebox.com
</java>
</target>
With these changes, should work fine. --DD
c***@onebox.com
2006-08-08 19:51:20 UTC
Permalink
Post by Dominique Devienne
Have you tried using -lib saxon.jar on the command line? This puts
saxon first on the classpath, which makes Trax load it instead of the
default JDK-provided XSLT engone.
Yes, to no effect.

As for the help with Plan B. Thanks, I've got that working on my computer (which had no problem with selecting the correct XSLT engine), but I've yet to try it on one of the recalcitrant boxes.

I'll get to it later today and report back.
--
Charles Knell
***@onebox.com - email



-----Original Message-----
From: Dominique Devienne <***@gmail.com>
Sent: Tue, 8 Aug 2006 10:16:56 -0500
To: "Ant Users List" <***@ant.apache.org>
Subject: Re: Command line arguments with <java> task.
Post by Dominique Devienne
So far that problem is still unresolved.
Have you tried using -lib saxon.jar on the command line? This puts
saxon first on the classpath, which makes Trax load it instead of the
default JDK-provided XSLT engone.
Post by Dominique Devienne
<arg value="-l -a"/>
<arg line="-l -a"/>
To my eye, these appear to be indentical. Which one is wrong?
the 'value' one is wrong. "-l -a" is not an argument. "-l" and "-a" are.
Post by Dominique Devienne
<target name="gen-properties" depends="init">
<java classname="net.sf.saxon.Transform" fork="true">
<classpath>
<pathelement location="${env.SAXON_HOME}/saxon8.jar" />
</classpath>
<arg value="-o ${env.SARS_REPORTS_HOME}\lib\temp\pbd.xml" />
Use 'line' instead. Better yet, using

<arg value="-o" />
<arg file="${env.SARS_REPORTS_HOME}/lib/temp/pbd.xml" />

Notice the forward-slash. 'value' and 'line' are string-based args,
that don't assume anything about the args. 'file' knows it's a
filename, and "does the right thing" (TM) to convert into a proper
filename for the current platform.
Post by Dominique Devienne
<arg value="${env.SARS_REPORTS_HOME}/lib/federal-holidays.xml" />
<arg value="${env.SARS_REPORTS_HOME}/lib/previous-bus-day.xslt" />
Again, better to use 'file' above.
Post by Dominique Devienne
<arg value="dow=${day.of.week}" />
<arg value="span=${span}" />
<arg value="current-date=${current.date}" />
This is correct OTOH. Even if span (or the other properties) contain
spaces, you most likely want to pass it in as a single argument.
Post by Dominique Devienne
</java>
</target>
With these changes, should work fine. --DD

---------------------------------------------------------------------
To unsubscribe, e-mail: user-***@ant.apache.org
For additional commands, e-mail: user-***@ant.apache.org
Loading...