I'm wondering if it is possible to retrieve, in runtime, a version number of a jar from which the class comes from?
I know its possible to find jar from which the class comes from:
MyClass.class.getProtectionDomain().getCodeSource().getLocation().getPath();
but what about a version?
(assuming its not in the file name:) )
Go to the /opt/novell/sentinel/bin directory. At the command line, specify the ./versionreader.sh <path/jar file name>. Running the script without any arguments gives the version of the installed Sentinel server.
The jar command is a general-purpose archiving and compression tool, based on the ZIP and ZLIB compression formats. Initially, the jar command was designed to package Java applets (not supported since JDK 11) or applications; however, beginning with JDK 9, users can use the jar command to create modular JARs.
Press ⌘ Command + V to paste in your JAR file's path, and press ⏎ Return . This executes the command to extract the JAR file. Go back to the JAR file's location.
To unpackage a JAR, you need a program that can extract compressed files. Windows includes functionality for this, but you can also use file extraction software like 7-Zip or WinRAR to get the job done. Open the JAR file within the software, and you can browse all the folders and files within it.
Try this, it may be helpful:
String s = new String(); System.out.println(s.getClass().getPackage().getSpecificationVersion()); System.out.println(s.getClass().getPackage().getImplementationVersion());
Output:
1.7 1.7.0_25
import javax.mail.internet.InternetAddress; /** Display package name and version information for javax.mail.internet. */ public final class ReadVersion { public static void main(String... aArgs){ ReadVersion readVersion = new ReadVersion(); readVersion.readVersionInfoInManifest(); } public void readVersionInfoInManifest(){ InternetAddress object = new InternetAddress(); Package objPackage = object.getClass().getPackage(); //examine the package object String name = objPackage.getSpecificationTitle(); String version = objPackage.getSpecificationVersion(); //some jars may use 'Implementation Version' entries in the manifest instead System.out.println("Package name: " + name); System.out.println("Package version: " + version); } }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With