在嵌入式javascript中使用Ant变量

时间:2013-04-22 04:55:07

标签: javascript ant

我正在编写一些Ant脚本,并在我的脚本中使用ant-contrib.jar文件。 我的ant脚本内容遵循代码块,但不符合我的要求。

<if>
            <equals arg1="${require.html}" arg2="1"/>
            <then>
                <script language="javascript">
                <![CDATA[                       
                    println("<h3>Selected Project Directory: ${project.dir}</h3>");
                    println("<h3>Generated reports are at the location ${dir.report}</h3>");
                ]]>
                </script>
            </then>
        </if>   

我正在尝试在嵌入式JavaScript中使用带有Ant脚本的$ {project.dir}变量。这里使用脚本我试图生成html文件。 但浏览器上显示的输出如下:

Selected Project Directory: ${project.dir}
Generated reports are at the location ${dir.report}

预期产出:

Selected Project Directory: C:\Project
Generated reports are at the location C:\Report

1 个答案:

答案 0 :(得分:1)

The docs say只要该属性是有效的JavaScript标识符,您就可以直接引用它,就像它是范围内的var一样。由于你的包含一个点,你不能这样做,但你仍然可以这样访问它们:

println("<h3>Selected Project Directory: " + project.getProperty("project.dir") + "</h3>");