Package de.elo.utils
Class Version
java.lang.Object
de.elo.utils.Version
public class Version
extends java.lang.Object
This class provides access to the version information of a package.
The META-INF/MANIFEST.MF file must look like the following example. The version information is contained in a section that starts with the Package name. It must end with a "/": e. g.
We will only use the version information related to implementation. This class only reads the implementation version.
The META-INF/MANIFEST.MF file must reside in the JAR file which contains the package. If the application is started from a "classes" directory, the manifest file must be availiable at "classes"/META-INF/MANIFEST.MF.
To read the version number in a stand-alone application use this statements:
To read the version number in a servlet use the following statements:
The
The META-INF/MANIFEST.MF file must look like the following example. The version information is contained in a section that starts with the Package name. It must end with a "/": e. g.
Name: de/elo/utils/
. Attention: the package
name must contain slashes "/" instead of dots "." We will only use the version information related to implementation. This class only reads the implementation version.
###### begin MANIFEST.MF ######
Manifest-Version: 1.0
Created-By: 1.4.2_04 (Sun Microsystems Inc.)
Name: de/elo/utils/
Implementation-Title: ELO Utils
Implementation-Version: 4.0.2
Implementation-Vendor: ELO Digital Office GmbH
###### end MANIFEST.MF ######
The META-INF/MANIFEST.MF file must reside in the JAR file which contains the package. If the application is started from a "classes" directory, the manifest file must be availiable at "classes"/META-INF/MANIFEST.MF.
To read the version number in a stand-alone application use this statements:
Version ver = new Version("de.elo.yourpackage", null);
String verno = ver.getVersion();
To read the version number in a servlet use the following statements:
String classesDir = config.getServletContext().getRealPath("WEB-INF/classes");
Version ver = new Version("de.elo.yourpackage", classesDir);
String verno = ver.getVersion();
The
classesDir
enables us to read the version information in
debugging mode (JBuilder). Make sure, that the directory
"...WebContent/WEB-INF/classes" contains "META-INF/MANIFEST.MF".-
Field Summary
Fields Modifier and Type Field Description static java.lang.String
NO_VERSION
-
Constructor Summary
Constructors Constructor Description Version(java.lang.String packageName, java.lang.String classesDir2)
Constructor. -
Method Summary
Modifier and Type Method Description java.lang.String
getIntVersion()
Returns the version number of the package (Specification-Version).static java.lang.String
getSystemVersionString(java.lang.String version)
Get formatted ELO system version.java.lang.String
getVersion()
Returns the version number of the package (Implementation-Version).void
logVersion()
Writes all version information to the LOG filejava.lang.String
toString()
-
Field Details
-
NO_VERSION
public static final java.lang.String NO_VERSION- See Also:
- Constant Field Values
-
-
Constructor Details
-
Version
public Version(java.lang.String packageName, java.lang.String classesDir2)Constructor.
First we try to find the version information in the JAR file that contains the specified package.
If the JAR file is not found or it contains no version information, a property file named Version.properties is trying to be load in the given package. A valid Version.properties file contains a key "Version". If no Version.properties is found or it does not contain a version number, a MANIFEST.MF file is searched in the first directory of the CLASSPATH.
If CLASSPATH does not contain any directory, we look for a META-INF/MANIFEST.MF in the directory supplied in parameterclassesDir2
.- Parameters:
packageName
- Name of a package, e. g. de.elo.ixclassesDir2
- Directory that contains META-INF/MANIFEST.MF ornull
. If the caller runs as a servlet inside a debugger, this directory could be e. g.ServletContext.getRealPath("WEB-INF/classes")
.
-
-
Method Details
-
getVersion
public final java.lang.String getVersion()Returns the version number of the package (Implementation-Version).- Returns:
- Version number or
NO_VERSION
, if no version information was found.
-
getIntVersion
public final java.lang.String getIntVersion()Returns the version number of the package (Specification-Version).- Returns:
- InterfaceVersion number or
NO_VERSION
, if no interface version information was found.
-
logVersion
public final void logVersion()Writes all version information to the LOG file -
toString
public java.lang.String toString()- Overrides:
toString
in classjava.lang.Object
-
getSystemVersionString
public static java.lang.String getSystemVersionString(java.lang.String version)Get formatted ELO system version.- Parameters:
version
- Version number, e.g. 10.16.071- Returns:
- System version, e.g. "ELO System 10"
-