public final class Version extends Object
The property files only defines one property. Important is to switch resource filtering on in your POM for that properties file.
version=1.0.0
This property file may be processed by a Maven filter to provide the version from the pom.xml:
version=${pom.version}
If you save the file in src/main/resources/foo/bar/version.properties
you can use the version this way:
Version version = new Version("/foo/bar/version.properties");
version.load()
println(version.getVersion);
| Modifier and Type | Class and Description |
|---|---|
(package private) static class |
Version.PropertyNames
Available properties in the file.
|
| Modifier and Type | Field and Description |
|---|---|
private Properties |
properties
Properties.
|
private boolean |
propertiesLoaded
Indicates whether the properties are already loaded or not.
|
private String |
propertyFileName
Location of property file.
|
| Constructor and Description |
|---|
Version(String propertyFileName)
Private constructor for singleton.
|
| Modifier and Type | Method and Description |
|---|---|
String |
getVersion()
Get the version string.
|
void |
load()
Opens the properties file and loads it.
|
(package private) void |
loadImpl()
Encapsulates the file loading.
|
String |
toString()
Returns the version string.
|
private final String propertyFileName
private boolean propertiesLoaded
private final Properties properties
public Version(String propertyFileName)
propertyFileName - Location of file, e.g. /de/weltraumschaf/commons/version.properties.public void load()
throws IOException
IOException - On IO errors of the property file.void loadImpl()
throws IOException
IOException - On IO errors of the property file.public String getVersion()
null or emptyCopyright © 2014 Sven Strittmatter. All Rights Reserved.