在 Windows 上使用 Ant 生成 PDF 查看器
Spawn a PDF viewer using Ant on Windows
我正在使用 Apache Ant 构建我的 XML 到 PDF 管道。使用此构建文件的每台 PC 都有自己的 Adobe Acrobat 版本。如何让 Ant 在多个地方查找以找到正确的可执行路径?目前我正在对如下路径进行硬编码,但当新人使用它时必须更改它。感谢任何帮助。
<property name="browser" location="C:\Program Files (x86)\Adobe\Acrobat 11.0\Acrobat\Acrobat.exe"/>
<property name="file" location="${dstDir}/${output}"/>
<exec executable="${browser}" spawn="true">
<arg value="${file}"/>
</exec>
与其硬编码 Acrobat.exe 的路径,不如考虑让 Windows 运行 程序注册处理 PDF 文件。 cmd.exe
的start
命令可以这样做:
<!-- No need for the "spawn" attribute because the "start" command -->
<!-- will launch the PDF program without waiting. -->
<exec executable="cmd" failonerror="true">
<arg value="/c"/>
<arg value="start"/>
<!-- The first argument of "start" is "Title to display in -->
<!-- window title bar." This argument must be surrounded by -->
<!-- quotation marks. Since this code doesn't launch a -->
<!-- Command Prompt window, we give a dummy value. -->
<arg value='"unused title"'/>
<arg value="${file}"/>
</exec>
在美好的过去,当 nashorn ScriptManager 是 JDK 开箱即用的一部分时,这就像一个魅力:
<scriptdef name="browse" language="javascript">
<attribute name="uri"/>
<![CDATA[
var uri = attributes.get("uri");
java.awt.Desktop.getDesktop().browse(new java.net.URI(uri));
]]>
</scriptdef>
我正在使用 Apache Ant 构建我的 XML 到 PDF 管道。使用此构建文件的每台 PC 都有自己的 Adobe Acrobat 版本。如何让 Ant 在多个地方查找以找到正确的可执行路径?目前我正在对如下路径进行硬编码,但当新人使用它时必须更改它。感谢任何帮助。
<property name="browser" location="C:\Program Files (x86)\Adobe\Acrobat 11.0\Acrobat\Acrobat.exe"/>
<property name="file" location="${dstDir}/${output}"/>
<exec executable="${browser}" spawn="true">
<arg value="${file}"/>
</exec>
与其硬编码 Acrobat.exe 的路径,不如考虑让 Windows 运行 程序注册处理 PDF 文件。 cmd.exe
的start
命令可以这样做:
<!-- No need for the "spawn" attribute because the "start" command -->
<!-- will launch the PDF program without waiting. -->
<exec executable="cmd" failonerror="true">
<arg value="/c"/>
<arg value="start"/>
<!-- The first argument of "start" is "Title to display in -->
<!-- window title bar." This argument must be surrounded by -->
<!-- quotation marks. Since this code doesn't launch a -->
<!-- Command Prompt window, we give a dummy value. -->
<arg value='"unused title"'/>
<arg value="${file}"/>
</exec>
在美好的过去,当 nashorn ScriptManager 是 JDK 开箱即用的一部分时,这就像一个魅力:
<scriptdef name="browse" language="javascript">
<attribute name="uri"/>
<![CDATA[
var uri = attributes.get("uri");
java.awt.Desktop.getDesktop().browse(new java.net.URI(uri));
]]>
</scriptdef>