How can I get jars from class manifest

I have a runnable jar with two banks in the Class-Path entry of the manifest file:

Class-Path: module1-0.0.1-SNAPSHOT.jar base-0.0.1-SNAPSHOT.jar Main-Class: test.MySPI 

The program works fine, and all the dependencies in the indicated jars are executed. However, when I try to access the class path, there are no cans there:

 String classpath = System.getProperty("java.class.path"); String[] entries = classpath.split(System.getProperty("path.separator")); for (String entry : entries) { System.out.println("Entry: " + entry); } 

Only gives

 Entry: .\module2-0.0.1-SNAPSHOT.jar 

Is there any way to access the actual class path, since obviously the system is finding these banks in the path?

+4
source share
2 answers

Do you really need the location of the JAR files, or just need to download resources from them?

If you really want to load resources, you will be interested in java.lang.ClassLoader , its static method getSystemClassLoader() and the static method java.lang.Thread.currentThread().getContextClassLoader() .

If you want to find what it was because you wanted to read the version line with the file name Jar ... and if they were under your control anyway ... you can use Package.getPackage("my.package").getImplementationVersion() and arrange for the required values ​​recorded in the component Package.getPackage("my.package").getImplementationVersion() manifest.

+3
source

I think you will need to use the Manifest class to read in the MANIFEST.MF file and extract the Class-Path attribute using this class

+5
source

Source: https://habr.com/ru/post/1334182/


All Articles