How to get a resource in another jar

后端 未结 4 519
情书的邮戳
情书的邮戳 2021-01-14 14:24

I have a jar embedded in a bundle that needs to fetch a resource packaged with it like so:

MyBundle
  -\\ src
  -\\lib
    -\\MyEmbeddedJar
      -\\src
             


        
4条回答
  •  青春惊慌失措
    2021-01-14 14:57

    My assumptions are that:

    1. That I'm not quite sure I get how your description of the problem matches the diagram. Where is the *.jar file?
    2. The bundle that is attempting to access the embedded jar is the same bundle that contains the embedded jar.
    3. Per the OSGi agnosticism, I am assuming that the embedded jar is not explicitly exposed as part of the current bundle's classpath and that it is not loaded as another OSGi bundle.

    If the jar in question is itself a resource of the current classloader, then you would first need to get the jar as a resource or as an InputStream, such as with MyBundleClass.class.getResourceAsStream("/pathToJar.jar"); then wrap it with a java.util.jar.JarInputStream. Then, continue to call getNextJarEntry() until you find the JarEntry object where "someResource.xml".equals(jarEntry.getName()).

提交回复
热议问题