Packaging the component

The package component is a zip containing the UNO-IDL types registry (types.rdb) and a jar with the compiled classes. To generate this, we will create an Ant build file (build.xml) with the following code:

<?xml version="1.0"?>
<project name="Helloworld" default="package">
    <description>
            This ant file is only to package the Helloworld component
    </description>

 <property name="out.path" value="bin/ant"/>
 
    <!-- ================================= 
          target: package              
         ================================= -->
    <target name="package" depends="purge">
    
     <mkdir dir="${out.path}" />  
     <copy todir="${out.path}" file="types.rdb">
      <fileset dir="bin">
       <include name="**/*.class" />
      </fileset>
      <fileset dir="build">
   <include name="**/*.class" />
      </fileset>
     </copy>
     
     <jar basedir="${out.path}" includes="**/*"
      excludesfile="types.rdb"
      destfile="${out.path}/Helloworld.jar">
      <manifest>
       <attribute name="RegistrationClassName" 
        value="org.openoffice.helloworld.comp.HelloworldImpl"/>
      </manifest>
     </jar>
    
     <mkdir dir="${out.path}/META-INF" />
     <copy todir="${out.path}/META-INF" file="manifest.xml" />
     
     <zip destfile="${out.path}/helloworld.uno.pkg"
       basedir="${out.path}" 
       includes="Helloworld.jar,META-INF/manifest.xml,types.rdb" />
     
    </target>
 
    <!-- This target is provided only to clean up the build -->

    <target name="purge">
        <delete dir="${out.path}" />
    </target>
</project>

You will also need to create a manifest.xml file containing a description of the zip file. The syntax of these files is detailed in the OpenOffice.org Developer's Guide and will not be explained here. You just have to create the file at the project's root with the following XML code:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE manifest:manifest PUBLIC "-//OpenOffice.org//DTD Manifest 1.0//EN" "Manifest.dtd">

<manifest:manifest>
   <manifest:file-entry 
           manifest:full-path="Helloworld.jar" 
           manifest:media-type="application/vnd.sun.star.uno-component;type=Java"/>
   <manifest:file-entry 
           manifest:full-path="types.rdb" 
           manifest:media-type="application/vnd.sun.star.uno-typelibrary;type=RDB"/>
</manifest:manifest>

You are now ready to execute the newly created ant script to generate the package bin/ant/helloworld.uno.pkg. To perform this action, you will have to open the Ant view by selecting the WindowShow View Ant menu item. You now have a tab like the one presented by the illustration 12. In this view, click on the ant icon to add your build.xml file to the list of ant files. You can now execute the package target by double-clicking on it in the Ant view. The build output is also shown in the Eclipse console view.

Ant build files view
Illustration 12: Ant build files view

If the console show you a result similar to the one below, then your component has been successfully generated. To see the generated files you can switch to the Resource perspective: they are generated in the bin/ant folder which is hidden in the Java package explorer.

Buildfile: /home/chef/develOOoppement/eclipse/Helloworld/build.xml
purge:
package:
    [mkdir] Created dir: /home/chef/develOOoppement/eclipse/Helloworld/bin/ant
     [copy] Copying 4 files to /home/chef/develOOoppement/eclipse/Helloworld/bin/ant
      [jar] Building jar: /home/chef/develOOoppement/eclipse/Helloworld/bin/ant/Helloworld.jar
    [mkdir] Created dir: /home/chef/develOOoppement/eclipse/Helloworld/bin/ant/META-INF
     [copy] Copying 1 file to /home/chef/develOOoppement/eclipse/Helloworld/bin/ant/META-INF
      [zip] Building zip: /home/chef/develOOoppement/eclipse/Helloworld/bin/ant/helloworld.uno.pkg
BUILD SUCCESSFUL
Total time: 1 second