简体   繁体   中英

Ant load .properties file dynamically

By default when you use <loadproperties srcFile="fileDir"/> the properties are loading in the beginning of ant script execution.

My problem is that the .properties file does not exist in the beginning, as I copy it from other direction(changing it content according to other things). So the question is: can I somehow load .properties file in the middle of ant script dynamically???

loadproperties is just a normal Ant task. It is equivalent to multiple calls to the property task to set properties. You can call it at the beginning of the script, in the middle of a certain target, or anywhere else.

Therefore if the properties file is being dynamically filled during the execution and at some point in target targetX you'd like to load it, you would just call the task as usual:

<target name="targetX" >    
    <loadproperties srcfile="${pathToFile}" />          
</target>

Note that if you already loaded the properties before (at the very beginning of the Ant script), then the second load will not override property values that have been set in the first call to loadproperties (since properties are immutable). If you want to override them, you can use the var task from Ant-Contrib.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM