如何轉換的Java類名到使用Ant任務文件路徑?螞蟻:將類名的文件路徑
例如,給定屬性包含foo.bar.Duck
我想出去foo/bar/Duck.class
。
我試過(也失敗了),以<pathconvert>
和<regexpmapper>
的條款實施。
如何轉換的Java類名到使用Ant任務文件路徑?螞蟻:將類名的文件路徑
例如,給定屬性包含foo.bar.Duck
我想出去foo/bar/Duck.class
。
我試過(也失敗了),以<pathconvert>
和<regexpmapper>
的條款實施。
這裏的另一種方式,使用Ant resources和unpackagemapper
,這是專爲這一目的。相反的package mapper
也是可用的。
<property name="class.name" value="foo.bar.Duck"/>
<resources id="file.name">
<mappedresources>
<string value="${class.name}" />
<unpackagemapper from="*" to="*.class" />
</mappedresources>
</resources>
您可以通過屬性助手語法${toString:...}
,例如方式使用資源值:
<echo message="File: ${toString:file.name}" />
息率
[echo] File: foo/bar/Duck.class
這裏是一個可能的方式做到這一點:
<property name="class.name" value="foo.bar.Duck"/>
<loadresource property="file.name">
<string value="${class.name}" />
<filterchain>
<replaceregex pattern="\." replace="/" flags="g" />
<replaceregex pattern="$" replace=".class" />
</filterchain>
</loadresource>
這使得所需foo/bar/Duck.class
到file.name
財產。
我覺得使用ant腳本的JavaScript因爲這是更簡單
<property name="class.name" value="foo.bar.duck" />
<script language="javascript">
var className = project.getProperty("class.name");
println("before: " + className);
var filePath= className.replace("\\", "/");
println("File Path: "+filePath);
project.setProperty("filePath", filePath);
</script>
<echo message="${filePath}" />
注:在命名變量相同的參數e.g VAR wsPath可能會錯誤,它給了我!
該解決方案將工作**僅如果只有**的資源可以被其他地方找到。別的,用[@馬特](http://stackoverflow.com/a/9135198/1099452)的溶液中。 – lucasvc 2014-12-09 14:23:13