Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>You could use some of the features in the <a href="http://commons.apache.org/configuration/" rel="nofollow noreferrer">Apache Commons Configuration</a> package. It at least provides type access to your properties. </p> <p>There are only conventions in the traditional java properties file. Some I've seen include providing, like you said, an example properties file. Another is to provide the default configuration with all the properties, but commented out.</p> <p>If you really want to require something, maybe you're not looking for a properties file. You could use an XML configuration file and specify a schema with datatypes and requirements. You can use jaxb to compile the schema into java and read it i that way. With validation you can make sure the required properties are there.</p> <p>The best you could hope for is when you execute your application, it reads, parses, and validates the properties in the file. If you absolutely had to stay properties based and didn't want to go xml, but needed this parsing. You could have a secondary properties file that listed each property that could be included, its type, and whether it was required. You'd then have to write a properties file validator that would take in a file to validate as well as a validation schema-like properties file. Something like</p> <pre><code>#list of required properties required=prop1,prop2,prop3 #all properties and their types prop1.type=Integer prop2.type=String </code></pre> <p>I haven't looked through all of the Apache Configuration package, but they often have useful utilities like this. I wouldn't be surprised if you could find something in there that would simplify this.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload