Jos*_*seK 14
从该线程中,使用Ant <script>任务:
<target name="capitalize">
<property name="foo" value="This is a normal line that doesn't say much"/>
<!-- Using Javascript functions to convert the string -->
<script language="javascript"> <![CDATA[
// getting the value
sentence = project.getProperty("foo");
// convert to uppercase
lowercaseValue = sentence.toLowerCase();
uppercaseValue = sentence.toUpperCase();
// store the result in a new property
project.setProperty("allLowerCase",lowercaseValue);
project.setProperty("allUpperCase",uppercaseValue);
]]> </script>
<!-- Display the values -->
<echo>allLowerCase=${allLowerCase}</echo>
<echo>allUpperCase=${allUpperCase}</echo>
</target>
Run Code Online (Sandbox Code Playgroud)
产量
D:\ant-1.8.0RC1\bin>ant capitalize
Buildfile: D:\ant-1.8.0RC1\bin\build.xml
capitalize:
[echo] allLowerCase=this is a normal line that doesn't say much
[echo] allUpperCase=THIS IS A NORMAL LINE THAT DOESN'T SAY MUCH
BUILD SUCCESSFUL
Run Code Online (Sandbox Code Playgroud)
更新 WarrenFaith的注释,将脚本分成另一个目标,并将一个属性从被调用目标 传递回调用目标
使用ant-contrib jar中的antcallback
<target name="testCallback">
<antcallback target="capitalize" return="allUpperCase">
<param name="param1" value="This is a normal line that doesn't say much"/>
</antcallback>
<echo>a = ${allUpperCase}</echo>
</target>
Run Code Online (Sandbox Code Playgroud)
和capitalise任务使用传入param1从而
<target name="capitalize">
<property name="foo" value="${param1}"/>
Run Code Online (Sandbox Code Playgroud)
最终输出
[echo] a = THIS IS A NORMAL LINE THAT DOESN'T SAY MUCH
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
10692 次 |
| 最近记录: |