简体   繁体   中英

Reading resources of another jar file

I have three java jar files which can be run independently. Each file contains images resource. I want each of the programs to be able to read resource from each other program. Let's assume they are in the same directory, when the program "A" is run I want to be able to read resources file inside file "B" or "C".

There may be a more elegant way of doing this with classloaders/etc.

However, JAR files are simply ZIP files with a different name. Assuming you know in advance the location of the folder in the JAR (probably src/main/resources ), you can simply unzip and read from there.

The class ZipEntry will allow you to do this, without needing any extra libraries: https://docs.oracle.com/javase/8/docs/api/java/util/zip/ZipEntry.html

Like I say, however, there is likely a better way of doing this.

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