简体   繁体   中英

How to read a resource in one java package (osgi bundle) from within another

I have a resource file(abc.yaml) in package abc.test

abc.test
       src
         main
           resources
             abc.yaml

i want to read this resource from within another package(xyz.test.util.Utils.java).

xyz.test src main java xyz test uril Utils.java

I tried

IOUtils.toString(RestApiUtil.class.getResourceAsStream("/abc.yaml"), "UTF-8");

Seems this is not feasible as it refers to the resources in xyz.test package.

Is there any way which i can get this done? Given that abc.test cannot have a dependency on xyz.test as xyz.test has a dependancy to abc.test

您可以在abc.yaml旁边放置一个类,比如说XY.java,然后使用

IOUtils.toString(XY.class.getResourceAsStream("abc.yaml"), "UTF-8");

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM