Created
March 7, 2018 09:50
-
-
Save learning-frog/f7fd5b56dd13812ce4737c09c4acfe4c to your computer and use it in GitHub Desktop.
Check which jar is used at runTime
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Class theClass = Cluster.class; | |
| // Find the path of the compiled class | |
| String classPath = theClass.getResource(theClass.getSimpleName() + ".class").toString(); | |
| System.out.println("Class: " + classPath); | |
| // Find the path of the lib which includes the class | |
| String libPath = classPath.substring(0, classPath.lastIndexOf("!")); | |
| System.out.println("Lib: " + libPath); | |
| // Find the path of the file inside the lib jar | |
| String filePath = libPath + "!/META-INF/MANIFEST.MF"; | |
| System.out.println("File: " + filePath); | |
| // We look at the manifest file, getting two attributes out of it | |
| Manifest manifest = new Manifest(new URL(filePath).openStream()); | |
| Attributes attr = manifest.getMainAttributes(); | |
| System.out.println("Manifest-Version: " + attr.getValue("Manifest-Version")); | |
| System.out.println("Implementation-Version: " + attr.getValue("Implementation-Version")); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment