문제

I am running a GUI application (A.jar). Then I add a plugin (B.jar) to this GUI(A.jar). Now I want to access the manifest.mf file in B.jar. I tried B.class.getResourceAsInputStream("/META-INF/MANIFEST.MF"). However, what I got is the manifest.mf in A.jar, not in B.jar.

Anyone can give me some hints on this problem? Thanks so much.

도움이 되었습니까?

해결책

It is the case that the general class loader will take the path the comes first on the class path, and evidently A.jar comes first, before B.jar.

String someUniqueResourceInBJar = "...";
URL url = B.class.getResource(someUniqueResourceInBJar);
url = new URL(url.getPath().replaceFirst(someUniqueResourceInBJar + "$", "")
    + "META-INF/MANIFEST.MF";
url.openStream();

The url will be something like "jar:file://.../B.jar!META-INF/MANIFEST.MF".


Alternatively getting the class URL:

URL url = b.class.getProtectionDomain().getCodeSource().getLocation();
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top