Possible to search for files in a jar file?


I would like to search for certain files that are in a specific jar file. Is there a way to do this?

Right now I've been using FilenameIndex to search for certain files, but some of those files are in a jar file.



FilenameIndex does include the contents of jar files. If you don't see those files returned as results, please check that you're using the correct GlobalSearchScope for your queries.

If you know in which jar the files are, it might be easier to iterate the contents of the jar file using JarFileSystem and access the files directly.



Thanks for your help. I see it working when I add the jar in question as a content root, but not when it's just in a folder in the project. Are there any conditions that determine if the jar file is indexed?

For reference, the jar contains various js files and I am searching for one specifically like this:

FilenameIndex.getFilesByName(project, "dojo.js", GlobalSearchScope.projectScope(project));


projectScope does not include any libraries, it only includes the project content. allScope() includes both project contents and libraries.
Jar files that are neither project roots nor libraries will not be indexed; however, using JarFileSystem to access their contents will work.


Thanks! That clears things up for me.


Please sign in to leave a comment.