Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do i get jars from manifest's Class-Path-entries

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

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

The program runs fine and all dependencies in the referenced jars are met. However, when I try to access the class path, the jars are not 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 a way of accessing the actual classpath, since obviously, the system finds those jars on the path?

like image 853
David Göransson Avatar asked Feb 25 '23 11:02

David Göransson


1 Answers

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

like image 197
a_horse_with_no_name Avatar answered Mar 08 '23 11:03

a_horse_with_no_name