How to get a resource in another jar

后端 未结 4 485
情书的邮戳
情书的邮戳 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条回答
  •  -上瘾入骨i
    2021-01-14 15:03

    I'm going to accept @Angelo's solution as it gave me the idea on how to work around this, though, I'd like to add more information in - thus my answer.

    My work around was to add another constructor to SomeClass that takes in a java.net.URL instance. I also copied someResource.xml into the bundle's root.

    I then updated the instantiation of SomeClass in the bundle like so:

    new SomeClass( FileLocator.find( Activator.getDefault().getBundle(), new Path( "./someResource.xml" ), new HashMap< String, String >() ) );
    

    This seems like a pretty big hack to me. What if I could not edit the contents of SomeClass ? I guess I would have to unpack it or I'd be forced to wrap it into it's own bundle?

提交回复
热议问题