public final class VersionUtil extends Object
Modifier and Type | Method and Description |
---|---|
static String |
getDetailedVersion(Class<?> cls)
Gets the detailed version from the project or library the provided
class belongs to.
|
static String |
getDetailedVersion(Class<?> cls,
String fallback)
Gets the detailed version from the project or library the provided
class belongs to.
|
static String |
getVersion(Class<?> cls)
Gets the version from the project or library the provided class belongs
to.
|
static String |
getVersion(Class<?> cls,
String fallback)
Gets the version from the project or library the provided class belongs
to.
|
public static String getVersion(Class<?> cls)
Gets the version from the project or library the provided class belongs to. This method attempts to read that version information from the class package implementation details, normally found in jar manifest files.
The manifest is often created when the code is packaged for distribution.
For instance, if you use Maven, you can ask it to automaticall store
implementation details with the manifest file when creating a jar file
by setting addDefaultImplementationEntries
set
to true
(see
https://maven.apache.org/shared/maven-archiver/).
If developing (not yet packaged), an attempt is made to locate a pom.xml and load the version from it.
cls
- the class used to extract versionnull
if not foundpublic static String getVersion(Class<?> cls, String fallback)
Gets the version from the project or library the provided class belongs to. This method attempts to read that version information from the class package implementation details, normally found in jar manifest files.
The manifest is often created when the code is packaged for distribution.
For instance, if you use Maven, you can ask it to automaticall store
implementation details with the manifest file when creating a jar file
by setting addDefaultImplementationEntries
set
to true
(see
https://maven.apache.org/shared/maven-archiver/).
If developing (not yet packaged), an attempt is made to locate a pom.xml and load the version from it.
cls
- the class used to extract versionfallback
- text to return when no version could be foundpublic static String getDetailedVersion(Class<?> cls)
Gets the detailed version from the project or library the provided class belongs to. This method attempts to read that version information from the class package implementation details, normally found in jar manifest files.
The manifest is often created when the code is packaged for distribution.
For instance, if you use Maven, you can ask it to automaticall store
implementation details with the manifest file when creating a jar file
by setting addDefaultImplementationEntries
set
to true
(see
https://maven.apache.org/shared/maven-archiver/).
If developing (not yet packaged), an attempt is made to locate a pom.xml and load the version from it.
cls
- the class used to extract versionpublic static String getDetailedVersion(Class<?> cls, String fallback)
Gets the detailed version from the project or library the provided class belongs to. This method attempts to read that version information from the class package implementation details, normally found in jar manifest files.
The manifest is often created when the code is packaged for distribution.
For instance, if you use Maven, you can ask it to automatically store
implementation details with the manifest file when creating a jar file
by setting addDefaultImplementationEntries
set
to true
(see
https://maven.apache.org/shared/maven-archiver/).
If developing (not yet packaged), an attempt is made to locate a pom.xml and load the version from it.
cls
- the class used to extract versionfallback
- text to return when no version could be foundCopyright © 2008–2023 Norconex Inc.. All rights reserved.