它可以通过调用一些脚本来完成
String.replaceAll()
在要转换为文件路径片段的字符串上。例如,使用以下
macrodef
:
<!-- =============================================================================
Replaces all '.' in groupId with '/' and put the result in a property
Attributes:
- groupId: maven groupId
- result: name of the property in which to put the result
============================================================================== -->
<macrodef name="pathFrom">
<attribute name="groupId"/>
<attribute name="result" default="path"/>
<sequential>
<local name="g"/>
<property name="g" value="@{groupId}"/>
<script language="javascript">
project.setProperty("@{result}", project.getProperty("g").replaceAll("\\.", "/"));
</script>
</sequential>
</macrodef>
<target name="test">
<property name="myGroup" value="com.github.org"/>
<pathFrom groupId="${myGroup}" result="tmp.path"/>
<echo message="converted from '${myGroup}' to '${tmp.path}'"/>
</target>
使用调用时使用以下输出
ant test
test:
[echo] converted from 'com.github.org' to 'com/github/org'