adding comment in .properties files

前端 未结 3 1112
佛祖请我去吃肉
佛祖请我去吃肉 2021-02-02 07:01

By using following block of code in build.xml file


   

        
相关标签:
3条回答
  • 2021-02-02 07:46

    Writing the properties file with multiple comments is not supported. Why ?

    PropertyFile.java

    public class PropertyFile extends Task {
    
        /* ========================================================================
         *
         * Instance variables.
         */
    
        // Use this to prepend a message to the properties file
        private String              comment;
    
        private Properties          properties;
    

    The ant property file task is backed by a java.util.Properties class which stores comments using the store() method. Only one comment is taken from the task and that is passed on to the Properties class to save into the file.

    The way to get around this is to write your own task that is backed by commons properties instead of java.util.Properties. The commons properties file is backed by a property layout which allows settings comments for individual keys in the properties file. Save the properties file with the save() method and modify the new task to accept multiple comments through <comment> elements.

    0 讨论(0)
  • 2021-02-02 07:48

    According to the documentation of the PropertyFile task, you can append the generated properties to an existing file. You could have a properties file with just the comment line, and have the Ant task append the generated properties.

    0 讨论(0)
  • 2021-02-02 07:50

    The property file task is for editing properties files. It contains all sorts of nice features that allow you to modify entries. For example:

    <propertyfile file="build.properties">
        <entry key="build_number"
            type="int"
            operation="+"
            value="1"/>
    </propertyfile>
    

    I've incremented my build_number by one. I have no idea what the value was, but it's now one greater than what it was before.

    • Use the <echo> task to build a property file instead of <propertyfile>. You can easily layout the content and then use <propertyfile> to edit that content later on.

    Example:

    <echo file="build.properties">
    # Default Configuration
    source.dir=1
    dir.publish=1
    # Source Configuration
    dir.publish.html=1
    </echo>
    
    • Create separate properties files for each section. You're allowed a comment header for each type. Then, use to batch them together into one single file:

    Example:

    <propertyfile file="default.properties"
        comment="Default Configuration">
        <entry key="source.dir" value="1"/>
        <entry key="dir.publish" value="1"/>
    <propertyfile>
    
    <propertyfile file="source.properties"
        comment="Source Configuration">
        <entry key="dir.publish.html" value="1"/>
    <propertyfile>
    <concat destfile="build.properties">
        <fileset dir="${basedir}">
            <include name="default.properties"/>
            <include name="source.properties"/>
        </fileset>
    </concat>
    
    <delete>
        <fileset dir="${basedir}">
             <include name="default.properties"/>
            <include name="source.properties"/>
        </fileset>
    </delete>      
    
    0 讨论(0)
提交回复
热议问题