我有以下ant build.xml文件,用于使用apache xsl-fo库生成pdf并使用okular应用(在Linux上)查看输出
<project name="pfd-generator" default="generate-pdf" basedir=".">
<property name="fop.home" value="/home/user/testpdf"/>
<property name="doc.type" value="${doctype}" />
<taskdef name="fop" classname="org.apache.fop.tools.anttasks.Fop">
<classpath>
<fileset dir="${fop.home}/lib">
<include name="*.jar"/>
</fileset>
<fileset dir="${fop.home}/build">
<include name="fop.jar"/>
<include name="fop-hyph.jar" />
</fileset>
</classpath>
</taskdef>
<target name="clean">
<delete includeemptydirs="true">
<fileset dir="docs" includes="**/*"/>
</delete>
</target>
<target name="generate-pdf" description="Generates a single PDF file">
<fop format="application/pdf"
xmlfile="./template_filled.xml"
xsltfile="./templates/template_${doctype}.xsl"
outdir="./docs"
basedir="./templates"
messagelevel="debug"
outfile="mypdf_${doctype}.pdf" />
</target>
<target name="run" depends="generate-pdf">
<exec executable="okular">
<arg value="./docs/mypdf_${doctype}.pdf"/>
</exec>
</target>
</project>
当我运行ant -Ddoctype=TYPE2 generate-pdf
时,由于我的xsl文件中有一些未定义的变量,因此不会生成pdf,但ant会返回BUILD SUCCESSFUL,如下所示:
user@host:~/testpdf ant -Ddoctype=TYPE2 generate-pdf
Buildfile: /home/user/testpdf/build.xml
generate-pdf:
[fop] ERROR: 'file:/home/user/testpdf/templates/template_TYPE2.xsl: line 75: Variabile o parametro 'rowheight2' non definito.'
[fop] FATAL ERROR: 'file:/home/user/testpdf/templates/template_TYPE2.xsl: line 75: Variabile o parametro 'rowheight2' non definito.'
[fop] :file:/home/user/testpdf/templates/template_TYPE2.xsl: line 75: Variabile o parametro 'rowheight2' non definito.
[fop] [ERROR] Anttask - Error rendering xml/xslt files: /home/user/testpdf/template_filled.xml, /home/user/testpdf/templates/template_TYPE2.xsl <org.apache.fop.apps.FOPException: file:/home/user/testpdf/templates/template_TYPE2.xsl: line 75: Variabile o parametro 'rowheight2' non definito.
[...]
[fop] Caused by: org.apache.fop.apps.FOPException: file:/home/user/testpdf/templates/template_TYPE2.xsl: line 75: Variabile o parametro 'rowheight2' non definito.
[fop] javax.xml.transform.TransformerConfigurationException: file:/home/user/testpdf/templates/template_TYPE2.xsl: line 75: Variabile o parametro 'rowheight2' non definito.
[fop] at org.apache.fop.cli.InputHandler.transformTo(InputHandler.java:296)
[...]
[fop] ... 24 more
[fop]
[fop] xml: /home/user/testpdf/template_filled.xml, xslt: /home/user/testpdf/templates/template_TYPE2.xsl -> /home/user/testpdf/docs/mypdf_TYPE2.pdf
BUILD SUCCESSFUL
Total time: 1 second
还有$?是0
仅当我在不存在的目标(即ant -Ddoctype=TYPE2 generate
我在哪里错了?我有一个脚本,可以在生成pdf的情况下打开pdf,但是如果没有生成pdf,则可以这样打开okular