Friday, January 25, 2013

How to bootstrap categories in Alfresco

If you want to categorize document it may result in the wish to have custom categories. In order to have a clean deployment of your Alfresco based application you really don't want to create these categories by hand. So what you need is to deploy the categories as part of the bootstrap of you application. This article explains how it works.

Let's assume that you followed this Blog and you know that it is possible to set up a repository project by using the AMP archetype which is provided via Maven. Then you already have the source folder which is 'config' which contains a subfolder which is named 'context''. Here the steps:

  • Create a new folder 'bootsrap' inside the 'context' folder
  • Create a new xml file named bootstrap-context inside the context folder and add the following to it:

 <?xml version="1.0" encoding="UTF-8"?>

<beans xmlns=""




    <bean id="${groupId}.${artifactId}.myBootstrap" class="org.alfresco.repo.module.ImporterModuleComponent" parent="module.baseComponent">


             <!-- Module Details -->

                <property name="moduleId" value="${pom.artifactId}" />

             <property name="name" value="myBootstrap" />

             <property name="description" value="For bootstrapping purposes" />

             <property name="sinceVersion" value="1.0" />

             <property name="appliesFromVersion" value="1.0" />


            <!-- Data -->

               <property name="importer" ref="spacesBootstrap"/>

               <property name="bootstrapViews">


                      <!-- Bootstrap the categories -->


                        <prop key="path">/cm:categoryRoot/cm:generalclassifiable</prop>

                        <prop key="location">alfresco/module/${artifactId}/bootstrap/my_categories.xml</prop>






  •  Now import the this context by adding the following line to the file 'config/module-context.xml':

    <import resource="classpath:alfresco/module/${artifactId}/context/bootstrap-context.xml"/>

  • Finally create an XML file named 'my_categories.xml which contains your category names like this:

 <view:view xmlns:view=""




      <cm:name>My Categories</cm:name>



            <cm:name>My first category</cm:name>



                  <cm:name>My second category</cm:name>



                  <cm:name>My third category</cm:name>



                  <cm:name>My last category</cm:name>







1 comment:

  1. You can also bootstrap complete folders by referencing an A(lfresco)C(ontent)P(ackage) instead the XML file.