Build your Firefox extension with Ant
You need to download 4 things:
<?xml version="1.0" ?>
<project name="your-project-name" default="createDistributionXPI">
<!-- Tool directories : *** Make sure you fix these to match your own environment *** -->
<property name="gecko_sdk_path" location="C:\Tools\gecko-sdk" />
<property name="buildtools_path" location="C:\Tools\buildtools" />
<!-- Derived tool directories -->
<property name="xpidl_exe" location="${gecko_sdk_path}/bin/xpidl.exe" />
<property name="IDLs_path" location="${gecko_sdk_path}/idl" />
<property name="libIDL_path" location="${buildtools_path}/windows/bin/x86" />
<!-- Project directories -->
<property name="src_dir" location="./src" />
<property name="build_dir" location="./build" />
<property name="dist_dir" location="./dist" />
<property name="components_dir" location="${src_dir}/components" />
<!-- Custom tasks -->
<taskdef resource="net/sf/antcontrib/antcontrib.properties"/>
<!-- Targets -->
<target name="createChromeJAR">
<zip destfile="${build_dir}/${ant.project.name}.jar" update="true"
basedir="${src_dir}/chrome"
includes="content/**, locale/**, skin/**"
/>
</target>
<target name="createComponentInterfaceXPTs">
<foreach target="compileIDL" param="idl_file">
<path>
<fileset dir="${src_dir}/components" includes="*.idl" />
</path>
</foreach>
</target>
<target name="compileIDL">
<exec executable="${xpidl_exe}" dir="${build_dir}">
<env key="Path" path="${env.Path};${libIDL_path}" />
<arg line="-m typelib -w -v -I ${IDLs_path} -I ${components_dir} ${idl_file}" />
</exec>
</target>
<target name="createDistributionXPI" depends="createChromeJAR, createComponentInterfaceXPTs">
<zip destfile="./dist/${ant.project.name}.xpi" update="true">
<zipfileset dir="${build_dir}" includes="${ant.project.name}.jar" prefix="chrome" />
<zipfileset dir="${src_dir}/components" includes="*.js" prefix="components" />
<zipfileset dir="${build_dir}" includes="*.xpt" prefix="components" />
<zipfileset dir="${src_dir}/defaults" includes="**" prefix="defaults" />
<zipfileset dir="${src_dir}" includes="install.rdf" />
</zip>
<copy file="${dist_dir}/${ant.project.name}.xpi" tofile="${dist_dir}/${ant.project.name}.xpi.zip" />
</target>
</project>
You need to change the 3 strings in blue toward the beginning of the file to match your project's name and your tool installations. Note that the dist/ directory will contain both an XPI file and a ZIP file. The ZIP file is just a copy of the XPI file with a .ZIP extension so that you can use WinZip to open it up and inspect its content.
Finally, you should create a batch file in your project's directory that looks something like this:
call c:\Tools\apache-ant-1.6.2\bin\ant
"C:\Program Files\Mozilla Firefox\firefox.exe"
One more note: it's probably convenient to put a link to your project's XPI file on Firefox's toolbar because you will need to reinstall the extension many times:
- Ant, from http://ant.apache.org/.
- Gecko SDK, from
ftp://ftp.mozilla.org/pub/mozilla.org/mozilla/releases/mozilla1.7.3/
or whichever is the latest version. Expand it to a directory, say C:\Tools\gecko-sdk. - Netscape build tools, from
http://ftp.mozilla.org/pub/mozilla.org/mozilla/source/wintools.zip.
Expand it to a directory, say C:\Tools\buildtools. - Ant-contrib tasks (of which we want the "foreach" task), from
http://ant-contrib.sourceforge.net/.
You only need to extract the .jar file from the download and put it in the lib subdirectory of your Ant installation.
- your-extension-dir/
- build.xml
- do.bat
- src/
- install.rdf
- chrome/
- content/
- contents.rdf
- *.xul, *.js,
- locale/
- en-US/
- ...
- skin/
- classic/
- ...
- content/
- components/
- *.idl
- *.js
- defaults/
- build/ (containing intermediate generated files)
- dist/ (containing the final distribution XPI file)
<?xml version="1.0" ?>
<project name="your-project-name" default="createDistributionXPI">
<!-- Tool directories : *** Make sure you fix these to match your own environment *** -->
<property name="gecko_sdk_path" location="C:\Tools\gecko-sdk" />
<property name="buildtools_path" location="C:\Tools\buildtools" />
<!-- Derived tool directories -->
<property name="xpidl_exe" location="${gecko_sdk_path}/bin/xpidl.exe" />
<property name="IDLs_path" location="${gecko_sdk_path}/idl" />
<property name="libIDL_path" location="${buildtools_path}/windows/bin/x86" />
<!-- Project directories -->
<property name="src_dir" location="./src" />
<property name="build_dir" location="./build" />
<property name="dist_dir" location="./dist" />
<property name="components_dir" location="${src_dir}/components" />
<!-- Custom tasks -->
<taskdef resource="net/sf/antcontrib/antcontrib.properties"/>
<!-- Targets -->
<target name="createChromeJAR">
<zip destfile="${build_dir}/${ant.project.name}.jar" update="true"
basedir="${src_dir}/chrome"
includes="content/**, locale/**, skin/**"
/>
</target>
<target name="createComponentInterfaceXPTs">
<foreach target="compileIDL" param="idl_file">
<path>
<fileset dir="${src_dir}/components" includes="*.idl" />
</path>
</foreach>
</target>
<target name="compileIDL">
<exec executable="${xpidl_exe}" dir="${build_dir}">
<env key="Path" path="${env.Path};${libIDL_path}" />
<arg line="-m typelib -w -v -I ${IDLs_path} -I ${components_dir} ${idl_file}" />
</exec>
</target>
<target name="createDistributionXPI" depends="createChromeJAR, createComponentInterfaceXPTs">
<zip destfile="./dist/${ant.project.name}.xpi" update="true">
<zipfileset dir="${build_dir}" includes="${ant.project.name}.jar" prefix="chrome" />
<zipfileset dir="${src_dir}/components" includes="*.js" prefix="components" />
<zipfileset dir="${build_dir}" includes="*.xpt" prefix="components" />
<zipfileset dir="${src_dir}/defaults" includes="**" prefix="defaults" />
<zipfileset dir="${src_dir}" includes="install.rdf" />
</zip>
<copy file="${dist_dir}/${ant.project.name}.xpi" tofile="${dist_dir}/${ant.project.name}.xpi.zip" />
</target>
</project>
Finally, you should create a batch file in your project's directory that looks something like this:
call c:\Tools\apache-ant-1.6.2\bin\ant
"C:\Program Files\Mozilla Firefox\firefox.exe"
One more note: it's probably convenient to put a link to your project's XPI file on Firefox's toolbar because you will need to reinstall the extension many times:
- Navigate Firefox to the dist/ directory containing the XPI (not to the XPI itself)
- Drag the link to the XPI file to the toolbar


7 Comments:
That sounds like a lot of work. You should install The Extension Developer's Extension instead.
-Ted
By
Ted Mielczarek, at 6:57 PM
Building sucks. Get Reloadchromezilla
By
Mitch Graw, at 7:51 AM
I came across you blog and thought you may find this site usefull. It has gas saving tips and where to find cheap gas. download site myspace.com
:)
By
Anonymous, at 10:33 PM
Want more clicks to your Adsense Ads on your Blog?
Then you have to check out my blog. I have found a FREE and Legitimate way that will increase your earnings.
Come Check us out. How to Boost Your AdSense Revenue
By
Google Page Rank 6, at 9:50 AM
Think that could give you some Search Engine popularity, and traffic???
By
Anonymous, at 2:08 AM
Greetings from North Cack-A-Lacky! I enjoyed your thoughts, although I give Firefox even a little more credit than you do, I think ;) See what I mean here: internet explorer 6 full download
By
Anonymous, at 10:17 PM
This site is great, nice job!!
I have a SEO info site. It is about va seo articles and stuff.
Drop by when you can, nice site here!
By
Anonymous, at 11:12 PM
Post a Comment
<< Home