Reputation: 16410
I want to know what is the use of .properties file and where it is used?
Currently I am doing dynamic web application with ANT and I have to use a .properties file when I set a property inside the "build.xml" file.
Upvotes: 14
Views: 27024
Reputation:
Properties are used to externalize the data which is configurable and if you put that data in your code you have to build the code each time you want to change the value of the property.
The main advantage of properties is that they are outside your source code and you can change them anytime.
To use properties refer to java.util.Properties
class.
Upvotes: 5
Reputation: 1698
Given your Ant file contains something like
<property file="build.properties"/>
<property name="prop1" value="value1"/>
if build.properties contains a line
prop1=valueFromPropertyFile
Then all references to prop1 will give you valueFromPropertyFile.
Best practices would be for all properties to be set in build.xml and have build.properties existence be optional to override specific settings for different environments. These properties can also be overridden on the command line with:
ant -Dprop1=valueFromCommandLine
Command line takes precedence over build.properties which takes precedence over whatever is in build.xml.
Specific examples in the web domain:
Upvotes: 3
Reputation: 34301
Properties files allow you to separate function (what the build.xml does) from the data it uses to perform that function (the properties).
For example, different developers on a project might have a different project root directories. The build would need to know which directory is the root, after which the functions it performs would be based on that directory. So rather than having a custom build.xml per developer, you would put this information in a properties file.
Upvotes: 3
Reputation: 346260
A .properties file is a simple collection of key-value pairs that can be parsed by the java.util.Properties
class.
Properties files are widely used for many purposes in all kinds of Java applications, often to store configuration or localization data.
ANT properties are an ANT-specific concept and not identical to properties files, though ANT properties can be read from such a file, usually in order to have a central point to store frequently used and changing configuration data. Then you can have a line like this in different ANT scripts:
<property file="foo.properties"/>
And all the scripts can then use those properties.
Upvotes: 19