Locating images within jars with Bash

I’ve been working with Netbeans in the last couple of days, and this post is an aide-memoir for one of the more onerous tasks I came across.  I wanted to re-use netbeans icons, but they were difficult to locate.   As usual stackoverflow had some useful information and what worked for me was the following bash command:
me@laptop:~/Applications/netbeans-6.9$ find . -name '*.jar' -type f | xargs -i bash -c "jar -tvf {}| tr / . | grep "saveAs.png" && echo {}"
847 Thu Jun 10 15:50:16 BST 2010 org.netbeans.modules.profiler.actions.resources.saveAs.png
847 Thu Jun 10 15:50:16 BST 2010 org.netbeans.modules.profiler.resources.saveAs.png
./profiler/modules/org-netbeans-modules-profiler.jar
847 Thu Jun 10 15:50:16 BST 2010 org.netbeans.modules.profiler.docs.helppages.img.saveAs.png
./profiler/modules/docs/org-netbeans-modules-profiler.jar

Which you can use to locate all .png images by replacing the “saveAs.png” as simply “.png”.   The same idea can be used for locating the module of a particular class, e.g.:
me@laptop:~/Applications/netbeans-6.9$ find . -name '*.jar' -type f | xargs -i bash -c "jar -tvf {}| tr / . | grep "SaveCookie" && echo {}"
1550 Thu Jun 10 15:36:04 BST 2010 org.netbeans.modules.versioning.diff.EditorSaveCookie.class
./ide/modules/org-netbeans-modules-versioning-util.jar
7462 Thu Jun 10 15:34:38 BST 2010 org.netbeans.modules.settings.SaveSupport$SaveCookieImpl.class
./platform/modules/org-netbeans-modules-settings.jar
295 Thu Jun 10 15:34:04 BST 2010 org.openide.cookies.SaveCookie.class
./platform/modules/org-openide-nodes.jar

From which it can be seen that the save cookie class is in the Nodes module.

2 thoughts on “Locating images within jars with Bash

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s