简体   繁体   中英

How to load resource file from dependency jar?

I have a Java project and a resource file (in src/main/resources). In this project I have a block of code that loads the file using getResourceAsStream from a class loader. Using this project as a dependency in another java project works fine.

When I use this as dependency for my Android project, this resource file cannot be found. Any ideas?

Try to use target jar classloader like this

ClassInOtherJar.class.getClassLoader().getResourceAsStream("NewFilename.xml")

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