The Alfresco SDK provides support for developers who wish to extend or customise the Alfresco platform.
It's been designed for the developer to get developing with minimal fuss for the following development scenarios:
Developing Alfresco Repository plug-ins such as:
Custom Actions / Conditions
Developing Applications against a standalone Alfresco server via Alfresco's Web Service API
Embedding Alfresco into existing Applications via Alfresco's Java Foundation API or standards-compliant JCR API
Some say typically, the SDK is used stand-alone, but how do you see the results without using the Alfresco web client? An Alfresco Release Installation is also required if performing any of the following:
Customising the Alfresco Web Client
Testing a custom Application that connects to a remote Alfresco Server
Deploying a tested custom plug-in to a remote Alfresco Server
You need to install both Alfresco, tomcat and Eclipse on the same system. Please note, SDK and Alfresco Version have to match in order to work correctly.
The SDK is not designed for re-building Alfresco i.e. it does not provide full build scripts and artifacts, therefore if you wish to develop bug fixes or extend the core functionality of the Alfresco platform, you should use the full Alfresco development environment provided in the Alfresco SVN Repository.
For Alfresco developer reference documentation visit the Developer Guide section of the Alfresco WIKI.
1. Prerequisites: Ensure the following development tools are installed...
JDK 1.6.x or JDK 1.5.x
Eclipse IDE 3.2+ (highly recommended)
MySql 184.108.40.206 (well, actually a Database of choice, but MySQL is recommended for development purposes)
2. Download the Alfresco Community Edition Release from SourceForge.
3. Download the Alfresco SDK from SourceForge. The SDK bundle is provided in .zip and .tar.gz formats. A separate package is available for each Alfresco release.
4. Unpack the downloaded package to a file system folder of your choice.
5. It's now installed.
An expanded Alfresco SDK contains the following directories and top-level files:
/bin - supporting dll's, exe's /doc - zipped Javadoc's for all pre-built libaries /extras - additional files - e.g. for MySQL db setup/removal /lib - pre-built Alfresco .jars /remote - Alfresco libraries required for access to a remote Alfresco server /server - Alfresco libraries required for embedding an Alfresco server /licenses - license files /src - zipped source code for all pre-built libraries /samples - template Eclipse projects for common development scenarios
Alfresco 3.2 can use either JDK 1.5 or 1.6, however 1.5 is now past it's end of life. (It works fine under 1.5, but installation sheets demand 1.6)
Select Window -> Preferences... menu option
Select Java -> Compiler preference in tree view
Select 1.6 in Compiler compliance level
Handle finding Win32NetBios
Add the alfresco bin folder to the system PATH.
Alternatively you theoretically should be able to add it to the java.library.path variable.
Import the Alfresco Eclipse Projects
The easiest and quickest way to explore the samples is via Eclipse. Each sample comes with its own Eclipse project which may be used as a template for future developments of a similar kind.
Select File -> Import...
Choose 'General -> Existing Projects into Workspace' import source and select Next
Choose Select root directory option and select Browse...
Navigate to the root file system folder where you unpacked the Alfresco SDK and select OK. Resist the temptation to navigate to samples, or you will not get SDK AlfrescoEmbedded and SDK AlfrescoRemote.
The Alfresco Projects are now listed under Projects as follows...
Check Build hints window for error. Known fixes are listed below
Modify Projects to run against Alfresco CE installation
Change the alfresco-global.properties file to:
Point to the location you installed content store for dir.root (ie C:/Alfresco/alf_data)
Uncomment dbname, dbpassword and MySql driver and url configurations
repeat above for all projects.
Reference libraries in SDK AlfrescoEmbedded project
In order to be able to run the SDK FirstFundationClient that references the SDK AlfrescoEmbedded project, it is necessary to reference in SDK AlfrescoEmbedded project all the libs in the 'dependencies' folder. Otherwise, when trying to run FirstFundationClient, you will get the error
Exception in thread 'main' org.springframework.beans.factory.CannotLoadBeanClassException: Cannot find class [org.alfresco.module.blogIntegration.BlogIntegrationServiceImpl] for bean with name 'blogIntegrationService' defined in class path resource [alfresco/blog-context.xml]; nested exception is java.lang.ClassNotFoundException: org.alfresco.module.blogIntegration.BlogIntegrationServiceImpl Caused by: java.lang.ClassNotFoundException: org.alfresco.module.blogIntegration.BlogIntegrationServiceImpl
Right click the SDK AlfrescoEmbedded project
Select Java Build Path link
Select the Libraries tab
Click Add JARs
Add all the jars present in the dependencies folder
Click OK twice
3.0 edition is missing the jlan jar and no one seems to have the correct version available anywhere. Use 2.9 version of SDK for less trouble.
Problem: version from 090705 was compiled with broken antscript, using absolute paths. Message: Project 'SDK AlfrescoEmbedded' is missing required library: 'G:\bamboo-home\xml-data\build-dir\ALF-COMMUNITY\root\build\assemble\sdk\lib\server\alfresco-core-3.2.jar'
Fix: use files from forum ( Manual fix) or check out the ant files (i guess, see Jira). If you use the files from the forum, don't forget to remove and re-import the projects.
SDK AlfrescoEmbedded - this project provides references to the libraries required for Alfresco Embedded use.
SDK AlfrescoRemote - this project provides references to the libraries required for Alfresco Remote use.
Each of the sample projects depends on one of the above.
SDK FirstFoundationClient - use of embedded Alfresco server via the Foundation API.
SDK FirstJCRClient - use of embedded Alfresco server via the JCR API.
SDK FirstWebServiceClient - use of remote Alfresco server via the Web Services API.
SDK JCRSamples - a mixture of JCR code samples including a simple WIKI demonstration.
SDK WebServiceSamples - a mixture of Web Service samples.
SDK CustomAction - how to develop a custom Action which may be deployed to an Alfresco Repository.
SDK CustomAspect - how to develop a custom Aspect with behaviour which may be deployed to an Alfresco Repository.
SDK CustomJSP - how to develop and configure a custom JSP for the Alfresco Web Client.
SDK CustomDialog - how to develop and configure a custom Dialog for the Alfresco Web Client.
SDK CustomWizard - how to develop and configure a custom Wizard for the Alfresco Web Client.
SDK CustomLogin - example demonstrating how to override Login page of the Alfresco Web Client.
SDK TaggingSample - example demonstrating how to adding document tagging behaviour to the Alfresco Web Client.
SDK Basic AMP - example demonstrating how to build an AMP (Alfresco Module Package) file.
Associate source code and Javadocs with Alfresco Libraries (optional)
Whilst developing against Alfresco it is useful to have access to Alfresco's source code and Java documentation. Within Eclipse, it's possible to associate such material with the libraries you're using.
For example, to associate source code and Javadoc with the Alfresco repository.jar in Eclipse...
Expand the SDK AlfrescoEmbedded project
Expand the Referenced Libraries (Note: do not select jar files under dependencies)
Select alfresco-repository.jar (Note: the jar files may not be in alphabetical order) and right-click select Properties
Select Javadoc Location and Javadoc in archive option
Select Browse and navigate to folder /doc/api within your Alfresco SDK install folder
Select repository-doc.zip and select Open
Select Validate... and either select Ok or Cancel depending upon whether you want to view the Javadoc in a Web browser
Select Java Source Attachment
Select External File... and navigate to folder /src within your Alfresco SDK install folder
Select repository-src.zip and select Open
Repeat above for in SDK Alfresco embedded:
alfresco-remote-api.jar (in 3.2. source only
SDK Alfresco Remote:
alfresco-web-service-client.jar, only sources are available
Not referenced in examples, but available in SDK directories:
The first sample to try is SDK FirstFoundationClient which demonstrates the use of an embedded Alfresco Repository via the the Java Foundation API. It simply connects to the Repository and creates a file in the 'Company Home' folder of the Web Client.
Before turning the ignition key, the first step is to ensure an appropriate database is setup for the Alfresco Repository, but this is only necessary if you did not install the Community edition version in addition to the SDK.
If you do not have a CE installed with a database already and you are using MySQL, the following may be issued from the shell script:
mysqladmin -u root -p create alfresco mysql -u root -p -e 'grant all on alfresco.* to 'alfresco'@'localhost' identified by 'alfresco' with grant option;' mysql -u root -p -e 'grant all on alfresco.* to 'alfresco'@'localhost.localdomain' identified by 'alfresco' with grant option;'
/org/alfresco/sample - Sample application consisting of FirstFoundationClient.java
Check the database connection details are correct (alfresco-global.properties) and then it's simply a case of running or debugging the FirstFoundationClient.java application within Eclipse.
The sample will initialise the Repository if it is the first client to connect to the Repository. In this case, the sample will take longer to execute as all Repository bootstrap data is installed into the database.
IMPORTANT NOTE - Alfresco CE tomcat can not be running at the same time as the samples. Shutdown tomcat and run the example. Then start Alfresco Tomcat again from programs menu, log in and you should see the results of the samples that ran. For instance, after running the FirstFoundationClient when you start Alfresco CE again and log in, under the Company Home space you will see the content created by the example.
Developing a Custom Plug-in
The projects SDK CustomAction and SDK CustomAspect demonstrate how to develop a plug-in for the Alfresco Repository. Plug-ins can be developed and tested with an embedded Alfresco Repository. Then, once satisfied, a plug-in can be packaged into a .jar which may then be deployed to any existing Alfresco installation. For example, the SDK CustomAspect project has a JUnit sample that tests the custom aspect by running an embedded Alfresco Repository using the Java Foundation API.
For each applicable SDK project, a build.xml file has been provided for packaging to a .jar file. See Packaging And Deploying Extensions for details on how to deploy extensions.
Executing the Web Services Examples
To execute any of the Web Service Samples for Java it is necessary to have an existing Alfresco Server installation to connect to. The easiest option is to install Alfresco.
The location of the Alfresco server to connect to is specified in the file webserviceclient.properties.
Note: This file is located in /alfresco for the SDK FirstWebServiceClient project and in /alfresco/extension for the SDK WebServiceSamples project.
The SDK contains ANT build scripts, with the option to integrate your extension into an existing Alfresco WAR file. For example, you can copy your Alfresco WAR file to one of the sample directories (such as samples/TaggingSample) and then run:
Alfresco extensions may be packaged into an AMP file for subsequent deployment into any existing Alfresco installation. The project demonstrates how to structure a project to build an AMP file.
The SDK Basic AMP project is a small SDK sample that show how classes and configuration files can be arranged to generate an Alfresco Module Package (AMP). For more details on the supported layout of files, see: AMP file
Use ANT to generate the AMP file from the build script:
ant -f build.xml
To deploy your SDK Basic Sample AMP, you can download the Module_Management_Tool into a working directory and then copy the generated AMP file and Alfresco WAR file into the same working directory.
The following example command will preview the change:
The modified Alfresco WAR can then be re-deployed back into your Alfresco server installation. If using Tomcat, you can shutdown Tomcat, delete the webapps/alfresco sub-directory and place the modified Alfresco WAR into webapps.
On re-starting the server, the Tomcat console will show that the custom class has been initialised during startup:
SDK Demo AMP class has been loaded
and also the module component has been installed and started:
13:13:51,712 INFO [repo.module.ModuleServiceImpl] Found 1 module(s). 13:13:52,509 INFO [repo.module.ModuleServiceImpl] Installing module 'sdkDemoAmp' version 1.0. DemoComponent has been executed
Building the SDK from SVN
You can build the SDK from SVN source using ANT:
ant -f continuous.xml distribute-sdk
Alfresco documentation is continuously being improved. If you see any issues with this documentation please feel free to fix via our WIKI editing capabilities. Again, if you get stuck, don't forget the Developer Resources. SDK Overview 3.2 Getting Started