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

前端 未结 2 1155
情话喂你
情话喂你 2021-01-13 23:19

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:          


        
2条回答
  •  刺人心
    刺人心 (楼主)
    2021-01-13 23:48

    Do you actually need the location of the JAR files, or do you just need to load resources from them?

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

    If you wanted to find what they were because you wanted to read the version string off the Jar file name ... and if they were under your control anyhow ... you might want to use Package.getPackage("my.package").getImplementationVersion() and organise to have the required values written into the Manifest of the component jars.

提交回复
热议问题