Dynamic property names in ant

时间秒杀一切 提交于 2019-12-11 08:54:36

问题


I am reading a file in ant and loading the properties through loadproperties. I am interested in using the value of a specific property, whose name is not known. I know that it follows a pattern because that is how I load the property.

I can echoproperties and see that it is being loaded.

But I dont know how to access its value, given that its name is actually a pattern rather that hardcoded.

How can I access this property's value to do some processing.

I hope this is clear. Please ask if I need to clarify some more.


回答1:


Take a look at ant-contrib package. Its propertycopy task will do what you need. If you need to resolve an arbitrary number of properties following an established pattern, you would use ant-contrib's propertycopy in conjunction with ant-contribs "for" task.

http://ant-contrib.sourceforge.net/tasks/tasks/index.html




回答2:


You should use Ant's script task.

I suggest using the beanshell script since it is pure java. For example, to print all properties for your project, use the following:

 <target name="echoprops">
    <script language="beanshell">
        System.out.println("All Properties: " + project.getProperties().keySet());
    </script>
 </target>

It should be easy to modify the above script to get the property you want.

To use this task, you will need to run the following in $ANT_HOME first:

ant -f fetch.xml script -Ddest=user

That will download all required optional jars to ~/.ant/lib .



来源:https://stackoverflow.com/questions/5263494/dynamic-property-names-in-ant

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!