Windows build script

From MozillaZine Knowledge Base
Jump to navigationJump to search
The printable version is no longer supported and may have rendering errors. Please update your browser bookmarks and please use the default browser print function instead.

This page is part of the extension development documentation project.

Ask your questions in MozillaZine Forums. Also try browsing example code.

Note: development documentation is in process of being moved to Mozilla Development Center (MDC).

These scripts can be used to build XPI packages for extensions automatically in Windows environment. See also bash build script.

Using 7-zip

Inspired by roachfiend's build script, which uses 7-Zip and Windows cmd/command.com shell.

Here’s what you need to do:

  • Install 7-Zip.
  • Copy C:\Program Files\7-Zip\7z.exe to C:\WINDOWS\system32 (This will put 7z.exe in your system’s path, which will make it accessible from the command prompt).
  • Replace following mentions of extension_name with your extension's name.
  • Copy the following script and paste it in a text editor and save it as build.bat in the directory above your extension's directory:
set x=extension_name
xcopy %x% build /i /e

xcopy build\content build\chrome\content /i /e
xcopy build\locale build\chrome\locale /i /e
xcopy build\skin build\chrome\skin /i /e
rmdir /s /q build\content
rmdir /s /q build\locale
rmdir /s /q build\skin

cd build\chrome
7z a -tzip "%x%.jar" * -r -mx=0
cd ..\..

rmdir /s /q build\chrome\content
rmdir /s /q build\chrome\locale
rmdir /s /q build\chrome\skin

replace chrome.manifest build

cd build
7z a -tzip "%x%.xpi" * -r -mx=9
cd ..

move build\%x%.xpi %x%.xpi

rmdir /s /q build
  • You can exclude certain files from being packed in (for example VSS's *.scc files) by inserting the following line just after the 2nd line above:
del build\*.scc /a:-d /s /f
  • Put the chrome.manifest file you want packed with your extension in the directory above your extension's directory.
  • Make sure your folder structure now looks like this (some items under extension_name/ are optional):
some_directory/
  build.bat
  chrome.manifest  (The one you want packaged)
  extension_name/
    chrome.manifest
    install.rdf
    components/
    defaults/
      preferences/
        mydefaults.js
    content/
      overlay.js
      overlay.xul
    locale/
      en-US/
        overlay.dtd
    skin/
      overlay.css


  • Now, you can build or modify your extensions easily. Just remember to put the build.bat and chrome.manifest files directly above your extension's development directory. Whenever you want to create your new file, just double-click build.bat, and your new extension will pop out in the same folder. Each time you use the build.bat script, it will delete your old file and create a new one.

Using WinRAR

Alternative Winrar version of the above script

  • Like for the 7zip version, you should copy Winrar.exe or Rar.exe to C:\WINDOWS\system32.
set x=%cd%
md build\chrome
cd chrome
winrar.exe a -r -ibck -m0 -afzip -n@"..\list.txt" "%x%.jar"
move "%x%.jar" "..\build\chrome\"
cd ..
copy install.rdf build
cd build
winrar.exe a -s -ibck -r -m5 -afzip "%x%.xpi"
move "%x%.xpi" ..\
cd ..
rd build /s/q
  • On the 4th line, you'll notice that there's an unusual switch: -n@"..\list.txt". This command tells winrar to include only the files that you have specified in a list.txt file. This switch is extremely useful for making sure that you don't include SVN or CVS files in your package. Below is an example list.txt file. You will want to modify this as necessary.
*.rdf
*.js
*.properties
*.xul
*.dtd
*.png
*.css
  • The list.txt file should be placed in the same directory as your build.bat file.
  • Of course, you may not need to exclude any files from your package, so in this case you can simply remove the -n@"..\list.txt" switch.