Reputation: 1650
I plan to create a global properties file for use across the application, and several properties files available only for specific classes and methods. Is there any particular industry standard for naming the property files?
Upvotes: 16
Views: 18829
Reputation: 20036
The naming is more complex if you consider also localization.
See Java doc for java.util.ResourceBundle
:
baseName + "_" + language + "_" + script + "_" + country + "_" + variant
Examples:
MyResource_fr_FR
MyResource_fr_CA
MyResource_fr_CH
MyResource_en_Latn_US_WINDOWS_VISTA
MyResource_en_Latn_US_WINDOWS
MyResource_en_Latn_US
MyResource_en_Latn
MyResource_en_US_WINDOWS_VISTA
MyResource_en_US_WINDOWS
MyResource_en_US
MyResource_en
Upvotes: 5
Reputation: 5072
To my knowledge, there is no set rule.
The naming convention I go by is if it is a properties for a single class, I use {ClassName}.properties
, otherwise I use {WhatIsItUsedFor}.properties
, and occasionally if it's for a single application, {ApplicationName}.properties
. I have a preference for CamelCase; others prefer lowercase.
For the names of properties themselves, if granularity is possible, I use something like
{ClassName}.{MethodNameIfNeeded}.{IntendedVariable}={value}
Do realize the more property files you have, the more potential maintenance issues you create. Some are better off consolidating to a single properties file, using the property/value naming convention (above) to single-out any classes requiring their own configuration.
Upvotes: 13
Reputation: 894
Not really. Name the file with a .properties extension (I've also seen .prp).
I would recommend against using a "global" properties file, and instead maintain like configurations in segregated files, i.e.:
database.properties
smtp.properties
messages.properties
Upvotes: 3
Reputation: 5916
Short answer: no
Typically you'd name the global properties 'myapp.properties'. Have a look around at some confgiration frameworks, see if they do what you want. Such as commons-configuration.
Upvotes: 5
Reputation: 160191
No; name them something meaningful to the context in which they'll be used.
You'll see things like "applicationResources.properties", "messages.properties", etc. right alongside filenames that have more business-specific meanings, like "account.properties".
Upvotes: 5