How to get VirtualFile reference to the resource from jar file
How to:
1. Get list of property files in the project library / all project libraries (for example, as VirtualFile[] array)?
2. Get VirtualFile reference to the file in the project library by relative path (for example, path is com/mycompany/resources/Errors.properties)?
Please sign in to leave a comment.
Alexei wrote:
You can start here:
LibraryTable modulelibs = ModuleRootManager.getInstance(module)
.getModifiableModel().getModuleLibraryTable();
LibraryTablesRegistrar tables = LibraryTablesRegistrar.getInstance();
LibraryTable projlibs = tables.getLibraryTable(project);
LibraryTable applibs = tables.getLibraryTable();
For #1 you can call
Library.getRootProvider().getRootProvider().getUrls(OrderRootType.ALL_TYPES),
and use string concatenation and VfsUtil or VirtualFileSystem to find
the files based on urls.
For #2 you can iterate through libraries and call
Library.getFiles(OrderRootType.ALL_TYPES).
But I'm not sure how to find which libraries a module is actually
depending on.
Does VirtualFile provide search facilities (for example, by extension)? Or do I need to iterate through file tree (using the VirtualFile.getChildren() method) only?
I think you can call Library.getFiles(..) to get a list of all known
files in the library.
Alexei wrote: