How To Structure An Extension Project

From AlfrescoWiki

Jump to: navigation, search

Back to Contributors Guide

Note: With 2.0 release, Alfresco introduced AMP files, a way to create modular extensions for Alfresco. That is the recommended way to write extensions. See more information at Category:AMP Files.

Contents

[edit] Code Separation

When writing an Alfresco extension it is a good idea to organise your code and configuration into a separate project area.

Keeping your code separate from Alfresco core code will ensure that future upgrade's of Alfresco will cause minimal migration issues for your extensions

[edit] Source Organisation

It is recommended that extension source should be structured in the following way.

  /ProjectName
     /source
        *java source code package structure*
     /config
        /alfresco
           /extesion
              *configuration files*
     /web
        /jsp
           *custom jsp*
        /WEB-INF
           *faces custom config*
     /lib
        *3rd party libs required by extension*
     build.xml 

Following this pattern will ensure consistency across Alfresco extension projects.

[edit] Ant build scripts

An any build script should be provided for an extension project. This should contain targets that will build, package and integrate the extenstion into the web application.

Here is an example build.xml that has been taken from the SDK.

  <?xml version="1.0"?>

  <project name="My Project Name" default="package-extension" basedir=".">	
     
     <property name="project.dir" value="."/>
     <property name="build.dir" value="${project.dir}/build"/>
     <property name="web.dir" value="${project.dir}/web" />
     <property name="package.file.jar" value="${build.dir}/custom-login.jar"/>
     <property name="package.file.zip" value="${build.dir}/custom-login.zip"/>	
     
     <target name="package-jar">
        <delete file="${package.file.jar}" />
        <jar destfile="${package.file.jar}">
           <fileset dir="${build.dir}" excludes="*.zip"/>
        </jar>
     </target>   
     
     <target name="package-extension" depends="package-jar">
        <delete file="${package.file.zip}" />
        <zip destfile="${package.file.zip}">
           <zipfileset file="${package.file.jar}" prefix="WEB-INF/lib" />
           <zipfileset dir="${web.dir}" />
        </zip>
     </target>
  
     <target name="integrate-extension" depends="package-extension">
        <available file="alfresco.war" type="file" property="alfresco.war.present" />
        <fail unless="alfresco.war.present"
           message="Could not find alfresco.war, please copy it to ${basedir}" />
        <zip destfile="alfresco.war" update="true">
           <zipfileset file="${package.file.jar}" prefix="WEB-INF/lib" />
           <zipfileset dir="${web.dir}" />
        </zip>
     </target>

  </project>

[edit] Eclipse

Eclipse is the IDE of choice at Alfresco, however there is no reason to limit development to Eclipse only if this is not the environment you are familiar with.

If Eclipse is used then the .project file is commonly provided with the source.