How to fiddle with Firefox .jar files relatively easily

November 22, 2005

A lot of Firefox's code is actually written in various interpreted languages, especially JavaScript, and Firefox extensions are pretty much all interpreted. This means that you can do a lot of Firefox and extension hacking without ever having to rebuild from source; you just zap the interpreted files in place in your installed copy.

Firefox doesn't leave all of these files sitting around for you to edit; it bundles them up in various .jar files (pretty much all in the chrome/ subdirectory). Fortunately .jar files are just ZIP archives. The easy way to modify files in them is:

  1. unzip the relevant jarfile somewhere (I usually use chrome/ itself, but I live dangerously)
  2. edit the unpacked files to taste
  3. run 'zip -f .../<whatever>.jar' in the root of where you unpacked the jarfile to 'freshen' it with your changes
  4. restart Firefox to test things.

(There are recipes for running Firefox from unpacked versions of the .jar files, but they require some black magic.)

(Figuring out which is the relevant jarfile (and the relevant source files) is beyond the scope of this entry; I suggest unpacking jarfiles and poking around. Also, see the Mozilla knowledge base at http://kb.mozillazine.org/.)


Comments on this page:

From 192.88.60.254 at 2005-11-23 10:36:37:

Fortunately .jar files are just ZIP archives.

Rather, jar files are ZIP archives with a few special metadata files in the META-INF/ directory. In fact, because of those files I'd be a bit paranoid about using zip on them directly and would instead use the jar command (which accepts generally the same options as the unix command tar, and which does sensible things if you call it with the option --help) to replace the files.

-- DanielMartin

By cks at 2005-11-23 12:38:27:

At least on Unix, Firefox's .jar files don't seem to have any META-INF/ directory, and Firefox builds them with the zip program.

(It appears to make some use of META-INF/ for storing digital signatures, judging from comments in the source code. But this is unlikely to be applicable once you start changing those files, since you can't re-sign them.)

From 62.14.222.29 at 2006-01-30 16:54:12:

Thanks for the tip! Why/how I couldn't find it in mozilla.org is beyond me!

Austin Powers: "I also like to live dangerously."

Dealer: "20 beats your 4."

Written on 22 November 2005.
« Why I don't write 'if (NULL == foo)' in C code
A quick outline of Firefox extension structure »

Page tools: View Source, View Normal, Add Comment.
Search:
Login: Password:
Atom Syndication: Recent Comments.

Last modified: Tue Nov 22 02:27:23 2005
This dinky wiki is brought to you by the Insane Hackers Guild, Python sub-branch.