Alfresco Documentation
Published on Alfresco Documentation (https://docs.alfresco.com)

Home > Alfresco SDK 2.1.0

Alfresco SDK 2.1.0

The Alfresco SDK is a Maven based development kit that provides an easy to use approach to developing applications and extensions for Alfresco. This documentation covers version 2.1 of the Alfresco SDK.

With this SDK you can develop, package, test, run, document and release your Alfresco extension project. It is important to note that while previous versions of the Alfresco SDK were based around Ant, the latest versions of the SDK are based on Maven.

Links to documentation for previous versions are available on this page [1].

The Alfresco SDK 2.1 includes a number of Maven archetypes. These archetypes aim to provide a standardized approach to development, release, and deployment of Alfresco extensions.

Project documentation, website, and support

From version 2.0 and up, releases for the Alfresco SDK are available in Maven Central.

The Alfresco SDK source code is hosted on GitHub [2].

The Alfresco SDK issue tracking is hosted on GitHub [3].

The Alfresco SDK forum for support is hosted on Alfresco Forums [4].

  • What's new? [5] This section describes new features in this version of the Alfresco SDK.
  • Introduction to the Alfresco SDK [6] This section of the documentation introduces you to the SDK.
  • Getting Started with the Alfresco SDK [7] This section of the documentation takes you through getting set up to work with the Alfresco SDK. The Alfresco SDK itself does not need to be installed (as it is based around Maven), but there are some prerequisites that will need to be made available.
  • Maven Archetypes - Command Reference [8] There are three Maven archetypes on which the Alfresco SDK can base the generation of projects. This section contains the Maven command reference for these projects.
  • Rapid Application Development (RAD) [9] These tutorials cover how to employ the RAD features of the Alfresco SDK.
  • Advanced Topics [10] This section goes through more advanced topics that you might come in contact with when you have been working with an SDK project for a while. We will have a look at how you can add more custom modules to an All-in-One project, how to bring in standard Alfresco modules such as Records Management (RM) and SharePoint Protocol (SPP) support, configuring SSL, and more.
  • Upgrading [11] This section of the documentation walks through how to upgrade your project to use a newer version of Alfresco. It also takes you through the process of upgrading your project to use a newer version of the SDK.
  • Using MySQL [12] The Alfresco SDK can be configured to use a MySQL database server rather than the default option of the H2 database engine.

What's new?

This section describes new features in this version of the Alfresco SDK.

What's new in Alfresco SDK 2.1

  • Support for Solr 4
  • Regression testing Share Webapp with Alfresco Share Page Object (PO) tests
  • Functional testing of Custom Pages with Alfresco Share PO
  • Rapid Application Development (RAD) improvements:
    • New alfresco:refresh-repo goal for alfresco-maven-plugin for automatic refresh of repository (alfresco.war)
    • New alfresco:refresh-share goal for alfresco-maven-plugin for automatic refresh of Share (share.war)
  • Automatic JavaScript compression
  • Custom package name can be used when generating projects
  • Records Management profile 'rm' removed, now included as other AMPs in the repository and Share WAR POMs
  • Run script for Windows now available (run.bat)
  • Upgraded to Community 5.0.d and Enterprise 5.0.1 (JDK8)
  • Fixed DB initialization error (dbObject cannot be null)
  • Fixed blank Admin Console bug

What's new in Alfresco SDK 2.0

  • Name changed from Maven Alfresco SDK to Alfresco SDK.
  • New Share AMP archetype.
  • RAD in Eclipse and IntelliJ.
  • Now requires Maven 3.2.2
  • RAD with Spring Loaded.
  • Support for JRebel has been deprecated.
  • Introduction of enterprise profile option -Penterprise.

What was new in Alfresco SDK 1.1.1

  • Bug fixes.

What was new in Alfresco SDK 1.1.0

  • Runs in Tomcat7 (replaces Jetty)
  • Remote running of JUnit
  • JRebel integration
  • Improved IDE integration

What was in Alfresco SDK 1.0.x

  • Use of Alfresco POMs
  • Relied on a number of components:
    • The SDK parent POM providing full Alfresco project lifecycle feature, to be added as a <parent> in your projects
    • Archetypes like the AMP or all-in-one providing sample project to kickstart your Alfresco development and boost it with best practices
    • The Alfresco Maven Plugin to manage AMP packaging and dependencies
    • Alfresco Platform Distribution POM can (optionally) be used to provide centralized <dependencyManagement> on a particular Alfresco version / edition (Community / Enterprise)
    • The Alfresco Artifacts Repository provides backing for this SDK. Check the Alfresco Wiki for Community / Enterprise access information
  • Embedded Jetty server and H2 database

What was in Maven Alfresco Lifecycle

  • First implementation of Alfresco Maven SDK (Now deprecated)
  • No use of Alfresco POMs
  • Available archetypes and plugins:
    • maven-alfresco-extension-archetype to create WAR packaged webapps that can provide all Maven lifecycle and features
    • maven-alfresco-share-archetype to create and manage Alfresco Share customization webapps
    • maven-alfresco-share-module-archetype to create and manage Alfresco Share custom dashlets, pages as JARs
    • maven-alfresco-amp-archetype to create maven-amp-plugin managed web apps, which can provide all Maven lifecycle and features to Alfresco modules. The maven-amp-plugin is also used as a replacement to MMT to unpack AMPs into WARs builds, using the Maven dependency mechanism provided by the maven-amp-plugin
  • Embedded Jetty server and H2 database to run Alfresco or Share
  • Possible to use Maven standard dependency management to pull in AMPs in your build
  • Further information [13]
Parent topic: Alfresco SDK 2.1 [14]

Introduction to the Alfresco SDK

This section of the documentation introduces you to the SDK.

You will learn about the different Maven Archetypes that can be used to generate Alfresco extension projects. This section also walks through what SDK version is compatible with what Alfresco version. And you will find links to some useful community resources.

  • Introduction to Maven archetypes [15] There are three Maven archetypes that can be used to generate Alfresco extension projects.
  • Compatibility matrix [16] Alfresco SDK has several versions and compatibility with Alfresco versions varies.
  • Community resources [17] This section lists some of the excellent community resources that are available to help you master the Alfresco SDK.
Parent topic: Alfresco SDK 2.1 [14]

Introduction to Maven archetypes

There are three Maven archetypes that can be used to generate Alfresco extension projects.

The following project types, and archetypes, are available:

  • Alfresco Repository AMP: this archetype is used to create extensions for the Alfresco Repository Web Application (alfresco.war) in the form of Alfresco Module Packages (AMP).
  • Alfresco Share AMP: this archetype is used to create extensions for the Alfresco Share Web Application (share.war) in the form of AMPs.
  • Alfresco all-in-one (AIO): this archetype is a multi-module project that leverages the Alfresco SDK's powerful capabilities to customize and run the full Alfresco platform embedded with all its components. The archetype does not require additional downloads and provides a perfect starting point for full-blown Alfresco projects.

You can view these archetypes when you obtain a list of archetypes from Maven Central:

mvn archetype:generate -Dfilter=org.alfresco:
Note: Note the use of a filter to display only archetypes in the namespace org.alfresco.
  • Repository AMP archetype [18] The Alfresco Repository (Repo) AMP Archetype generates a sample project for managing Alfresco Repository extensions/customizations. These extensions are packaged as Alfresco Module Packages (AMP).
  • Share AMP archetype [19] The Alfresco Share AMP Archetype generates a sample project for managing Alfresco Share extensions/customizations. These extensions are packaged as Alfresco Module Packages (AMP).
  • All-in-One archetype [20] The Alfresco All-in-One (AIO) Archetype is a multi-module project, leveraging Alfresco SDK's powerful capabilities to customize and run the full Alfresco platform embedded with all its components. The archetype does not require additional downloads, such as an Alfresco installer, and provides a perfect starting point for full-blown Alfresco projects where the final artifacts should be the customized alfresco.war and share.war.
Parent topic: Introduction to the Alfresco SDK [6]

Repository AMP archetype

The Alfresco Repository (Repo) AMP Archetype generates a sample project for managing Alfresco Repository extensions/customizations. These extensions are packaged as Alfresco Module Packages (AMP).

This archetype should be used to extend the Alfresco Repository web application (alfresco.war).

The following are typical use-cases for when this archetype should be used:
  • You work in a bigger team and want to develop, tag, and release a Repo module separately from the main Alfresco Extension project (All-in-One) that it is included in.
  • You want to add, and contain, an extra Repo module in an All-In-One Project (useful when you don't have a Nexus artifacts repo to which you can release individual repo AMPs).
  • You intend to build an Add-On, Component, Module etc that should be distributed independently.
If you intend to build an extension for the Alfresco Share web application, use the Share AMP archetype [21] instead.

The main features of this archetype are:

  • AMP packaging - the supported packing type for Alfresco extensions.
  • AMP dependency management in Maven.
  • Installation of AMPs into an Alfresco WAR.
  • Sample repository web script demonstrating how to implement a custom REST-based API.
  • Content Model Skeleton XML file ready to be filled in with your domain specific content model.
  • AMP Unit Testing support. Just run the standard mvn test and see your src/test/java Alfresco unit tests run. An sample Unit Test is provided in this archetype.
  • Run embedded in Tomcat with an embedded H2 database for demo purposes (-Pamp-to-war), rapid application development and integration testing.
    Important: This is not a supported stack, so it should only be used for development purposes.
  • Support for (remote) Junit and integration testing and Rapid Application Development. This uses spring-loaded. Project can easily be launched for this scenario using run.sh.
  • Easy to integrate with an IDE environment such as Eclipse and IntelliJ IDEA.
Parent topic: Introduction to Maven archetypes [15]

Share AMP archetype

The Alfresco Share AMP Archetype generates a sample project for managing Alfresco Share extensions/customizations. These extensions are packaged as Alfresco Module Packages (AMP).

This archetype should be used to extend the Alfresco Share web application (share.war).

The following are typical use-cases for when this archetype should be used:
  • You work in a bigger team and want to develop, tag, and release a Share UI module separately from the main Alfresco Extension project (All-in-One) that it is included in.
  • You want to add, and contain, an extra Share UI module in an All-In-One Project (useful when you don't have a Nexus artifacts repo to which you can release individual Share UI modules).
  • You intend to build an Add-On, Component, Module etc that should be distributed independently.
If you intend to build an extension for the Alfresco Repository web application, use the Repository AMP archetype [22] instead.

The main features of this archetype are:

  • AMP packaging - the supported packing type for Alfresco extensions.
  • AMP dependency management in Maven.
  • Installation of AMPs into an Alfresco WAR.
  • Sample Aikau page and widget to demonstrate how to develop new pages for the Alfresco Share UI.
  • AMP Unit Testing support. Just run the standard mvn test and see your src/test/java Alfresco unit tests run. An sample Unit Test is provided in this archetype.
  • Run embedded in Tomcat for demo purposes (-Pamp-to-war), rapid application development and integration testing.
    Important: Requires a running Alfresco Repository on localhost:8080.
  • Easy to integrate with an IDE environment such as Eclipse and IntelliJ IDEA.
Parent topic: Introduction to Maven archetypes [15]

All-in-One archetype

The Alfresco All-in-One (AIO) Archetype is a multi-module project, leveraging Alfresco SDK's powerful capabilities to customize and run the full Alfresco platform embedded with all its components. The archetype does not require additional downloads, such as an Alfresco installer, and provides a perfect starting point for full-blown Alfresco projects where the final artifacts should be the customized alfresco.war and share.war.
The following are typical use-cases for when this archetype should be used:
  • You are going to start on a project for a client and need an Alfresco extension project that can produce the final customized Alfresco WAR and Share WAR artifacts.
  • Your project needs access to the full regression testing suite for the Alfresco Share UI.
  • Your project needs access to the functional testing based on the Alfresco Share Page Object (PO) library.
  • When testing with the RAD features you need Solr to be running.
Note that if you are going to develop an addOn, reusable component, module, and so on, that should be distributed independently, then have a look at the AMP projects instead. For Alfresco repository extensions see Repository AMP [22] and for Alfresco Share extensions see Share AMP [21].

The main features of the AIO archetype are:

  • AMP packaging for repository and share extensions - the supported packing type for Alfresco extensions.
  • AMP dependency management in Maven.
  • Automatic installation of AMPs into Alfresco WAR and Share WAR.
  • Easy to include extra AMPs and have them included in the WARs.
  • Out-of-the-box Alfresco extensions such Records Management (RM), SharePoint Protocol (SPP), Media Management etc easily included in the same way as custom AMPs for consistency.
  • AMP Unit Testing support. Just run the standard mvn test and see your src/test/java Alfresco unit tests run. An sample Unit Test is provided in this archetype.
  • Alfresco Share Regression Testing - you don't have to write tests to protect against regression in out-of-the-box Share UI functionality, just use the -Prun,regression-testing profiles
  • Custom Functional Testing - Utilize the Alfresco Share Page Objects (PO) to write your own custom web page testing (example test included), use the -Prun,functional-testing profiles
  • Run a full Alfresco stack (that is, alfresco.war, share.war, solr4.war) embedded in Tomcat using the H2 database for demo purposes (-Prun), rapid application development and integration testing.
    Important: This is not a supported stack, so it should only be used for development purposes.
  • Support for (remote) Junit and integration testing and Rapid Application Development. This uses spring-loaded. Projects can easily be launched for this scenario using run.sh.
  • Seamless IDE integration with Eclipse and IntelliJ IDEA.
Parent topic: Introduction to Maven archetypes [15]

Compatibility matrix

Alfresco SDK has several versions and compatibility with Alfresco versions varies.

It is recommended you use the latest version of the Alfresco SDK where possible.

The following table shows compatibility between Alfresco SDK and versions of Alfresco.

Alfresco version Maven Alfresco Lifecycle (deprecated) Maven SDK 1.0.x (deprecated) Maven SDK 1.1.x Alfresco SDK 2.0.x Alfresco SDK 2.1.x
3.2.2 - 4.1.1.x Compatible (but not supported) Not available Not available Not available Not available
4.1.x (x >= 2) Not available Compatible (but not supported) Not available (SDK 1.1.0 does not work with Alfresco 4.1.2-4.1.5 using Solr Search Subsystem [23]. It is possible to use Alfresco 4.1.6 and greater, or use Lucene Search Subsystem) Not available Not available
4.2.x Not available Not available Compatible and supported Not available Not available
5.0 and 5.0.c Not available Not available Not available Compatible and supported Not available
5.0.1+ and 5.0.d+ Not available Not available Not available Compatible and supported Compatible and supported
Important: Note that Alfresco 4.1.x requires Java 6, Alfresco 4.2.x and Alfresco 5.0 require Java 7. Alfresco 5.0.1 and 5.0.d requires Java 8. Note also that Alfresco SDK works only on Linux, Windows or Mac.
Parent topic: Introduction to the Alfresco SDK [6]

Community resources

This section lists some of the excellent community resources that are available to help you master the Alfresco SDK.

Some community resources that are worth trying out:

Link Description
Alfresco SDK on GitHub [2] Where you can clone the code, submit issues and read community documentation.
Order of the Bee [24] Quoting from the site: We are an independent organization of the Alfresco community. We are here to promote Alfresco Community Edition and aggregate the best from the community for you.
Mind the Gab [25] News, thoughts and tutorials from one of the main developers behind the Alfresco SDK.
Alfresco SDK 2.0 Deep Dive [26] Article that takes a look at the "behind the scenes" stuff used by the Alfresco SDK 2.0.
Ole Hejlskov's Alfresco SDK 2.0 Beta screencast [27] Screencast showing use of the three main archetypes of the SDK in Eclipse. Also demonstrates some important features of the SDK such as hot reloading of code.
Parent topic: Introduction to the Alfresco SDK [6]

Getting Started with the Alfresco SDK

This section of the documentation takes you through getting set up to work with the Alfresco SDK. The Alfresco SDK itself does not need to be installed (as it is based around Maven), but there are some prerequisites that will need to be made available.
This section is split up into three areas:
  • Installing software that is a prerequisite for running the SDK successfully
  • Getting the SDK working from the command line
  • Getting the SDK working from IDEs
  • Before you begin [28] There are some points you need to be aware of before you start using the Alfresco SDK.
  • Installing and configuring software [29] This section describes how to install and configure the software on which the SDK depends.
  • Creating a project [30] The following tutorials take you step by step through how to create and run projects using the standard archetypes provided by the Alfresco SDK.
Parent topic: Alfresco SDK 2.1 [14]

Before you begin

There are some points you need to be aware of before you start using the Alfresco SDK.

Some things to do and note before you start:

  1. Check the What's New [31] page to orientate yourself to the latest features of the SDK.
  2. Check the compatibility matrix [32] to make sure that you have the right version of the SDK for your version of Alfresco.
  3. Make sure that you understand the different types of Maven archetypes that are available. Check the Maven Archetypes summary [33] to make sure that you use the right one for your extension.
Parent topic: Getting Started with the Alfresco SDK [7]

Installing and configuring software

This section describes how to install and configure the software on which the SDK depends.

You'll need to download and install the following tools and libraries, if you don't already have them:

  1. The Java Software Development Kit (JDK) version 8
  2. Apache Maven 3.2.5
  3. Spring Loaded
  • Install Spring Loaded [34] The Alfresco SDK's Rapid Application Development (RAD) features uses Spring Loaded.
  • Install JDK [35] The Alfresco SDK is based on Maven, which requires the JDK to be installed. This topic steps you through installing the JDK and verifying its installation.
  • Setting JAVA_HOME [36] Before using the Alfresco SDK, you need to set your JAVA_HOME environment variable to a suitable value, using the correct mechanism for your operating system.
  • Install Maven [37] The Alfresco SDK is now based around Maven (formerly it used Ant). To use the Alfresco SDK you need to have Maven installed.
  • Setting MAVEN_OPTS & M2_HOME [38] Before using the Alfresco SDK, you need to set your MAVEN_OPTS and M2_HOME environment variables to suitable values using the correct mechanism for your operating system.
  • Using Alfresco Enterprise Edition (Optional) [39] By default the Alfresco SDK will use Alfresco Community artifacts but it can be configured to use Enterprise artifacts. This requires access credentials for the Alfresco Private Repository, and modification of several Maven configuration files.
  • Verify install [40] Before proceding to use the Alfresco SDK, you should do one final check of your system to ensure you have the prerequisites correctly installed.
Parent topic: Getting Started with the Alfresco SDK [7]

Install Spring Loaded

The Alfresco SDK's Rapid Application Development (RAD) features uses Spring Loaded.
There are no pre-requisites for this installation.
Spring Loaded [41] is a Java agent (represented by a JAR file) that enables class reloading in a running JVM. It will enable you to update a Java file in your Alfresco extension project and then see the effect of the change directly in a running Alfresco-Tomcat-JVM instance without having to re-build JARs, AMPs, and WARs and re-deploying them, saving you loads of time.
  1. Download the Spring Loaded JAR from here [41].
  2. Copy JAR to some directory.

    There is no specific installation needed, just copy the JAR to a permanent place where you can refer to it.

You now have the Spring Loaded JAR readily available in a directory.
Parent topic: Installing and configuring software [29]

Install JDK

The Alfresco SDK is based on Maven, which requires the JDK to be installed. This topic steps you through installing the JDK and verifying its installation.
There are no pre-requisites for this installation.
To use the Alfresco SDK most effectively, and to align with what JDK is used by the default Alfresco versions in the SDK, you need to have Oracle JDK 1.8 installed. Maven requires that the JDK be installed - the Java run-time alone is not sufficient [42].

Checking for the availability of the JDK.

  1. Check if you have the JDK already installed. Go to your command line and type the following command:

                            
    javac -version
                        

    You will see a message such as the following, if you have the JDK installed:

                            
    javac 1.8.0_45
                        
    Important: Make sure you use javac when you test if JDK is installed and not java, which tests if JRE is installed.

    If you get "command not found" you need to install the JDK. Also if you have a version of the JDK prior to 1.8 you will need to install 1.8 or above. It is possible to have multiple versions of the JDK installed (and multiple Java run-times). You will later see how you can configure your JAVA_HOME variable so that Maven uses the correct version of the JDK.

Downloading the JDK.

  1. Download the JDK 8 from the Oracle JDK site [43].

Installing the JDK.

  1. Carefully review the Oracle JDK 8 installation guide [44] as appropriate for your system.
  2. Install the JDK, following the Oracle instructions.

Verifying the JDK is successfully installed.

  1. Go to your command line and type the following command:

                            
    javac -version
                        

    This will display information such as the following:

                            
    javac 1.8.0_45
                        

    To be extra sure you should also check your Java run-time by entering the following command:

                            
    java -version
                        

    This will display information such as the following:

                            
    java version "1.8.0_45"
    Java(TM) SE Runtime Environment (build 1.8.0_45-b14)
    Java HotSpot(TM) 64-Bit Server VM (build 25.45-b02, mixed mode)
                        

    Double check that the version of Java installed is correct (1.8 or above).

You now have JDK 1.8 installed and you have verified that you are running the correct version of Java.
Parent topic: Installing and configuring software [29]

Setting JAVA_HOME

Before using the Alfresco SDK, you need to set your JAVA_HOME environment variable to a suitable value, using the correct mechanism for your operating system.
Setting the JAVA_HOME environment variable ensures that the correct JDK is accessed. This is especially important where you have multiple JDKs installed on your system.
  1. On Mac OS X you can edit your .bash_profile file and add something similar to the following (the exact version you are using may vary):

    export JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk1.8.0_45.jdk/Contents/Home

    Restart the terminal session or run source .bash_profile to activate the environment variable.

    Attention: Note that the actual value you specify here will depend on which JDK you have installed, and the resultant directory name.
  2. On Linux you can edit your .bashrc file and add something similar to the following:

    export JAVA_HOME=/usr/lib/jvm/java-8-oracle

    Restart the terminal session or run source .bashrc to activate the environment variable.

    Attention: Note that the actual value you specify here will depend on which JDK you have installed, and the resultant directory name.
  3. On Windows, the exact procedure for setting environment variables varies depending on the version of Windows you are running. For example, the procedure for Windows XP can be found in the Microsoft Knowledgebase [45].

    Attention: Note that the actual value you specify here will depend on which JDK you have installed, and the resultant directory name.
  4. Ensure that the JAVA_HOME environment variable is set correctly, using a method suitable for your system. For example, on Mac OS X and Linux you can enter the following command:

    $ env |grep JAVA_HOME
    JAVA_HOME=/usr/lib/jvm/java-8-oracle
                        

    You will see the value that JAVA_HOME has been set to.

    Ensure that the result matches the value you specified in your shell configuration file (such as .bashrc).

    If you are on Windows you can use a command such as SET J to display environment variables starting with 'J'.

Your JAVA_HOME environment variable is now set, and you have verified it is reflected in your environment.
Parent topic: Installing and configuring software [29]

Install Maven

The Alfresco SDK is now based around Maven (formerly it used Ant). To use the Alfresco SDK you need to have Maven installed.
To be able to use Maven you need to have a suitable JDK installed. For this version of the SDK you should have JDK 1.7 installed.
To use the Alfresco SDK you need to have Maven installed. The version required is 3.2.5 and above.

Check for the availability of Maven.

  1. First, check to see if you already have the correct version of Maven installed. On your command line enter the following command:

    mvn --version
                

    If you get "command not found", or you have a version of Maven less than 3.2.5, you will need to install Maven or upgrade to 3.2.5 or above. In this case it is recommended you download the correct version of Maven (3.2.5+) from the official Maven website.

Downloading Maven.

  1. Download Maven from the Apache Maven project web site [46].

Installing Maven.

  1. Carefully review the platform-specific installation instructions in the Installing Maven [47] Sonatype documentation.
  2. Install Maven using the platform-specific instructions provided in the Maven documentation.

Verifying Maven is correctly installed.

  1. Run the following command to verify Maven is correctly installed:

    mvn --version
                        

    This will display information such as the following:

    Apache Maven 3.2.5 (12a6b3acb947671f09b81f49094c53f426d8cea1; 2014-12-14T17:29:23+00:00)
    Maven home: /usr/local/apache-maven-3.2.5
    Java version: 1.8.0_45, vendor: Oracle Corporation
    Java home: /usr/lib/jvm/java-8-oracle/jre
    Default locale: en_GB, platform encoding: UTF-8
    OS name: "linux", version: "3.13.0-51-generic", arch: "amd64", family: "unix"
                        

    Check that the correct versions of Maven and the JDK are being used. If Maven is not using the correct version of the JDK, make sure you have set your JAVA_HOME environment variable, as described in the previous tutorial.

You have now installed Maven and verified that it is the correct version and is using the correct version of the JDK.
Parent topic: Installing and configuring software [29]

Setting MAVEN_OPTS & M2_HOME

Before using the Alfresco SDK, you need to set your MAVEN_OPTS and M2_HOME environment variables to suitable values using the correct mechanism for your operating system.
Setting M2_HOME specifies the home of Maven and is used by the script mvn (or mvn.bat on Windows). MAVEN_OPTS is used to configure a bit of extra memory for Maven as it will run an embedded Apache Tomcat application server with Alfresco Repo, Share, and Solr web applications deployed. It also sets the Spring Loaded Java Agent so it is available during Rapid Application Development (RAD).

Setting Variables.

  1. On Mac OS X you can edit your .bash_profile file and add the following:

    export M2_HOME=/opt/apache-maven-3.2.5
    export MAVEN_OPTS="-Xms1024m -Xmx1G -javaagent:/home/martin/libs/springloaded-1.2.3.RELEASE.jar -noverify"
                        
    Important: Refer to previous installation sections for in what directory Maven was installed and in what directory Spring Loaded was installed.

    Restart the terminal session or run source .bash_profile to activate the environment variables.

  2. On Linux you can edit your .bashrc file and add the following:

    See step 1 for Mac OS, do the same thing for Linux.

    Restart the terminal session or run source .bashrc to activate the environment variable.

  3. On Windows, the exact procedure for setting environment variables varies depending on the version of Windows you are running. For example, the procedure for Windows XP can be found in the Microsoft Knowledgebase [45].

    set M2_HOME=C:\Tools\apache-maven-3.3.1
    set MAVEN_OPTS=-Xms256m -Xmx1G -javaagent:C:\Tools\spring-loaded\springloaded-1.2.3.RELEASE.jar -noverify
                        
    Important: If the path to the Spring Loaded JAR contains spaces, then you might need to double quote it like -javaagent:"C:\My Tools\spring-loaded\springloaded-1.2.3.RELEASE.jar". Refer to previous installation sections for in what directory Maven was installed and in what directory Spring Loaded was installed.

    Restart the Windows terminal/console session.

Verifying Variables.

  1. Ensure that the MAVEN_OPTS and M2_HOME environment variables are set correctly, using a method suitable for your system. For example, on Mac OS X and Linux you can enter the following command:

    $ env|egrep "M2|MAV"
    MAVEN_OPTS=-Xms256m -Xmx1G -javaagent:/home/martin/libs/springloaded-1.2.3.RELEASE.jar -noverify
    M2_HOME=/usr/local/apache-maven-3.2.5   
                            
                        

    Ensure that the result matches the value you specified in your shell configuration file (such as .bashrc).

    If you are on Windows you can use a command such as set M to display environment variables starting with 'M'.

    C:\Users\mbergljung>set M
    M2_HOME=C:\Tools\apache-maven-3.3.1
    MAVEN_OPTS=-Xms256m -Xmx1G -javaagent:C:\Tools\spring-loaded\springloaded-1.2.3.RELEASE.jar -noverify
                            
                        
Your MAVEN_OPTS and M2_HOME environment variables are now set. Feel free to increase the specified memory settings if required, for example, if you get "out of memory" errors when running your projects.
Parent topic: Installing and configuring software [29]

Using Alfresco Enterprise Edition (Optional)

By default the Alfresco SDK will use Alfresco Community artifacts but it can be configured to use Enterprise artifacts. This requires access credentials for the Alfresco Private Repository, and modification of several Maven configuration files.
Important: To obtain access to the Alfresco Enterprise repository located here [48], please refer to this knowledge base article [49]. If you do not have access to this portal then please contact your Alfresco technical liaison representative within your company, or Alfresco directly [50].

Accessing the Alfresco Private Repository

The first matter to consider is to ensure that you have credentials for the Alfresco Private Repository, where the Enterprise artifacts are stored. In fact the private repository also includes all public artifacts too. Once you have suitable credentials you need to add support for Alfresco private repository to your configuration. This would typically be done by adding your access credentials to the settings.xml contained in your ~/.m2 directory (for Linux and OS X). On Windows 7 and Vista this resolves to <root>\Users\<username> and on XP it is <root>\Documents and Settings\<username>\.m2.

This procedure is explained in detail in the tutorial Configuring access to the Alfresco Private Repository [51].

  • Configuring access to Alfresco Private Repository [51] In order to be able to utilize Enterprise artifacts, it is necessary to allow Maven access to the Alfresco Private Artifacts Repository, where the Enterprise artifacts are maintained.
Parent topic: Installing and configuring software [29]

Configuring access to Alfresco Private Repository

In order to be able to utilize Enterprise artifacts, it is necessary to allow Maven access to the Alfresco Private Artifacts Repository, where the Enterprise artifacts are maintained.
You need to have permission to access the Alfresco private repository. Enterprise customers can obtain access credentials from Alfresco.
In order to allow Maven access to the Alfresco Private Repository, you must add your credentials to the Maven configuration. This is usually done by adding an entry to the settings.xml file, located in your .m2 directory.
  1. Obtain access credentials for the Alfresco Private Repository from Alfresco. This is only available for Enterprise-level customers.
  2. Change into your Maven configuration directory. For Linux and Mac OS X that will most likely be ~/.m2 for a configuration on a per-user basis, or for global configuration in <maven_install>/conf/. On Windows this would be located in %USER_HOME%/.m2/ for a per-user configuration, and %M2_HOME%/conf for a global configuration.
  3. Load settings.xml into your editor. Add the following new server configuration in the <servers> section:

                            
     <server>
       <id>alfresco-private-repository</id>
       <username>username</username>
       <password>password</password>
     </server>                        
                            
                        
    Important: You will need to replace the placeholder text with your real username and password as allocated by Alfresco. Make a note of the id value, as this will be referenced from the pom.xml you will edit later in order to tell Maven to fetch Enterprise artifacts from this repository.
    Attention: It is possible to use encrypted passwords here. See the official Maven documentation [52] for details on how to do this.

    At this point you have configured Maven to have access to the Alfresco Private Repository.

Parent topic: Using Alfresco Enterprise Edition (Optional) [39]

Verify install

Before proceding to use the Alfresco SDK, you should do one final check of your system to ensure you have the prerequisites correctly installed.
Check you have the JDK and Maven correctly installed, and the correct versions of both, and that Maven is configured to use the correct version of the JDK.
Check your configuration by running the command mvn --version. This will display information similar to the following:

Apache Maven 3.2.5 (12a6b3acb947671f09b81f49094c53f426d8cea1; 2014-12-14T17:29:23+00:00)
Maven home: /usr/local/apache-maven-3.2.5
Java version: 1.8.0_45, vendor: Oracle Corporation
Java home: /usr/lib/jvm/java-8-oracle/jre
Default locale: en_GB, platform encoding: UTF-8
OS name: "linux", version: "3.13.0-51-generic", arch: "amd64", family: "unix"
                

Make sure that the correct version of Maven is installed (3.2.5+) and that the correct version of the JDK is installed (1.8+). If you have multiple JDKs installed double check that Maven is using the correct version of the JDK. If you do not see this kind of output, and your operating system cannot find the mvn command, make sure that your PATH environment variable and M2_HOME environment variable have been properly set.

You are now ready to start using the Alfresco SDK.
Parent topic: Installing and configuring software [29]

Creating a project

The following tutorials take you step by step through how to create and run projects using the standard archetypes provided by the Alfresco SDK.

The tutorials show creation of projects using:

  1. Alfresco Repository AMP archetype - is this artifact for your project, read more here [22].
  2. Alfresco Share AMP archetype - is this artifact for your project, read more here [21].
  3. All-in-One archetype - is this artifact for your project, read more here [53].
  • Creating a Repository extension project (AMP) [54] The Alfresco Repository AMP maven archetype can be used to create a new Alfresco Module extension project for the alfresco.war.
  • Creating a Share extension project (AMP) [55] The Alfresco Share AMP maven archetype can be used to create a new Alfresco Module extension project for the share.war.
  • Creating an All-in-One (AIO) project (WARs) [56] The All-in-One maven archetype can be used to create a new multi-module project that will produce customized alfresco.war and share.war artifacts.
Parent topic: Getting Started with the Alfresco SDK [7]

Creating a Repository extension project (AMP)

The Alfresco Repository AMP maven archetype can be used to create a new Alfresco Module extension project for the alfresco.war. For more information about this project type see Repository AMP Archetype [18]
This task assumes that you have completed all instructions in Installing and configuring software [29].
This task shows how you can use the Repo AMP archetype of the Alfresco SDK to generate a repository extension module containing a simple example web script.
  1. Create a suitable directory in which to store all your Maven projects (if you have not already done so), such as alfresco-extensions.
  2. Change into your alfresco-extensions directory.
  3. Run the following command:

    mvn archetype:generate -Dfilter=org.alfresco:
    Important: As the archetypes are available via Maven Central you do not need to specify a catalog.

    You will be prompted to choose an archetype:

                        
    Choose archetype:
    1: remote -> org.alfresco.maven.archetype:alfresco-allinone-archetype (Sample multi-module project for All-in-One development on the Alfresco plaftorm. Includes modules for: Repository WAR overlay, Repository AMP, Share WAR overlay, Solr configuration, and embedded Tomcat runner)
    2: remote -> org.alfresco.maven.archetype:alfresco-amp-archetype (Sample project with full support for lifecycle and rapid development of Repository AMPs (Alfresco Module Packages))
    3: remote -> org.alfresco.maven.archetype:share-amp-archetype (Share project with full support for lifecycle and rapid development of AMPs (Alfresco Module Packages))
    Choose a number or apply filter (format: [groupId:]artifactId, case sensitive contains): : 
    
  4. Enter 2 to have Maven generate an Alfresco Repository Module Package (AMP) project.
  5. You will be prompted to choose an archetype version:

    Choose org.alfresco.maven.archetype:alfresco-amp-archetype version: 
    1: 2.0.0-beta-1
    2: 2.0.0-beta-2
    3: 2.0.0-beta-3
    4: 2.0.0-beta-4
    5: 2.0.0
    6: 2.1.0
    Choose a number: 6: 
                                                

    Press Enter to select the default (the most recent version).

  6. You will then be prompted to enter a value for the property groupId:

    Define value for property 'groupId': : com.acme

    Here we have specified com.acme representing the domain for a fictional company acme.com. Specify a groupId matching your company domain.

  7. You will then be prompted to enter a value for the property artifactId:

    Define value for property 'artifactId': : componentX-repo

    Here we have specified componentX-repo representing an X component with a specific extension for the Alfresco Repository. Try and name the Repository extensions in a way so it is easy to see what kind of extension it is for the alfresco.war application. Here are some example names for repo extensions so you get the idea: zip-and-download-action-repo, digital-signature-repo, business-reporting-repo, these repository extensions would typically have corresponding Share extensions if they also include user interface functionality. It is good practice to use the following naming convention for repository extensions: {name}-repo, where -repo indicates that this is an Alfresco Repository extension. Note, hyphens are typically used in artifact IDs.

  8. You will then be prompted to enter a value for the property package:

    Define value for property 'package':  com.acme: : com.acme.componentX

    Here we have specified com.acme.componentX representing an X component Java package. This package will be used for any example Java code generated by the archetype. It is good practice to keep all Java code you write under this package so it does not clash with other components/extensions. Any Spring beans generated by this archetype will use this package in the ID.

    Important: Java packages cannot have hyphens in them.
  9. You will then be prompted to enter Y to accept the values you have entered, or n to reject and change. Press Enter to accept the values.

    A new project directory containing a number of sub-directories and support files for the AMP will be created in the directory componentX-repo.

  10. Change into the freshly created componentX-repo directory and browse the various files and directories to see what has been created.

    The following directory structure has been created for you:

    componentX-repo/
    ├── pom.xml (Maven project file)
    ├── run.sh  (Mac/Linux script to have this AMP applied to the Alfresco WAR and run in Tomcat)
    ├── run.bat (Windows script to have this AMP applied to the Alfresco WAR and run in Tomcat)
    ├── src
    │   ├── main
    │   │   ├── amp (For more information about the AMP structure see: http://docs.alfresco.com/community/concepts/dev-extensions-modules-intro.html)
    │   │   │   ├── config
    │   │   │   │   └── alfresco
    │   │   │   │       ├── extension
    │   │   │   │       │   └── templates
    │   │   │   │       │       └── webscripts (Your Web Scripts should go under this directory)
    │   │   │   │       │           ├── webscript.get.desc.xml   (Sample Web Script that you can try out)
    │   │   │   │       │           ├── webscript.get.html.ftl
    │   │   │   │       │           └── webscript.get.js
    │   │   │   │       └── module
    │   │   │   │           └── componentX-repo (AMP Module ID)
    │   │   │   │               ├── alfresco-global.properties (Put default values for properties specific to this extension here) 
    │   │   │   │               ├── context
    │   │   │   │               │   ├── bootstrap-context.xml (Bootstrapping of content models, content, i18n files etc)
    │   │   │   │               │   └── service-context.xml (Your service beans go here)
    │   │   │   │               ├── log4j.properties
    │   │   │   │               ├── model
    │   │   │   │               │   ├── content-model.xml (Content model for your files)
    │   │   │   │               │   └── workflow-model.xml (Content model for workflow implementations)
    │   │   │   │               └── module-context.xml (Spring context file that is picked up by Alfresco)
    │   │   │   ├── module.properties (AMP module ID, Version etc)
    │   │   │   └── web (If your AMP has some UI the files would go here, unlikely now when the Alfresco Explorer UI is gone)
    │   │   │       ├── css
    │   │   │       │   └── demoamp.css
    │   │   │       ├── jsp
    │   │   │       │   └── demoamp.jsp
    │   │   │       ├── licenses
    │   │   │       │   └── README-licenses.txt
    │   │   │       └── scripts
    │   │   │           └── demoamp.js
    │   │   └── java (Your Java classes go here, this is where most of the module extension implementation code would go, you can remove the demo component)
    │   │       └── com
    │   │           └── acme
    │   │               └── componentX
    │   │                   └── demoamp  (Demo module component, can be removed)
    │   │                       ├── DemoComponent.java
    │   │                       └── Demo.java
    │   └── test
    │       ├── java
    │       │   └── com
    │       │       └── acme
    │       │           └── componentX
    │       │               └── demoamp
    │       │                   └── test  (Example test of the demo component, can be removed)
    │       │                       └── DemoComponentTest.java 
    │       ├── properties
    │       │   └── local
    │       │       └── alfresco-global.properties (environment specific configuration, the local env is active by default)
    │       └── resources
    │           ├── alfresco
    │           │   └── extension
    │           │       └── disable-webscript-caching-context.xml (file to disable server side JavaScript compilation to Java code)
    │           └── log4j.properties 
    └── tomcat
        └── context.xml  (Virtual Webapp context for RAD development)
    
  11. At this point, before you have made any changes, you can build the project by typing:

    mvn install                                
    Attention: Maven will ensure that all requirements are downloaded. This make take some time.

    The project will return with the message BUILD SUCCESS. You should see the AMP artifact installed in your local repository .m2/repository/com/acme/componentX-repo/1.0-SNAPSHOT/componentX-repo-1.0-SNAPSHOT.amp

  12. Run and Test the sample Web Script

    To test the Web Script you will need to start an embedded Tomcat and deploy the Alfresco WAR with the componentX-repo AMP applied. This can be done in two ways:
    1. With mvn clean install -Pamp-to-war
    2. Via the run.sh script (or run.bat on Windows), which does the same thing, plus making sure Spring Loaded library is available.
    Important: This will only run the customized Alfresco Repository application (alfresco.war), Alfresco Share UI (share.war) and Search (solr4.war) is not available. If you need those too then use the All-in-One project [57] instead.

    Let's start Tomcat via the script as follows (use run.bat on Windows):

    ./run.sh
    ...
    INFO: WSSERVLET12: JAX-WS context listener initializing
    Apr 30, 2015 10:04:39 AM com.sun.xml.ws.transport.http.servlet.WSServletDelegate <init>
    INFO: WSSERVLET14: JAX-WS servlet initializing
    2015-04-30 10:04:39,152  WARN  [shared_impl.util.LocaleUtils] [localhost-startStop-1] Locale name in faces-config.xml null or empty, setting locale to default locale : en_GB
     Apr 30, 2015 10:04:39 AM org.apache.coyote.AbstractProtocol start
    INFO: Starting ProtocolHandler ["http-bio-8080"]
    2015-04-30 10:05:24,545  INFO  [management.subsystems.ChildApplicationContextFactory] [SearchScheduler_Worker-1] Starting 'Transformers' subsystem, ID: [Transformers, default]
     2015-04-30 10:05:24,741  INFO  [management.subsystems.ChildApplicationContextFactory] [SearchScheduler_Worker-1] Startup of 'Transformers' subsystem, ID: [Transformers, default] complete
    
    Important: You may first need to make the shell script executable using the command chmod +x run.sh.
  13. Once the web application has started (it may take a little while), point your browser at http://localhost:8080/alfresco/service/sample/helloworld to test the web script. The web script should return the following text: Message: Hello World!
  14. If you are prompted to login, then use username admin and a password admin.
  15. Configure Enterprise Edition (Optional)

    So far we have used the project with its default configuration, which is using Alfresco Community edition 5.0.d. If you are going to work with the Enterprise edition then you need to do the following:

    1. Decide what Enterprise version you will be using, if you are going to use version 5.0.1 then you are set as that is the default Enterprise version. If you want to use another version then open up the componentX-repo/pom.xml file and uncomment the <alfresco.version>5.0.d</alfresco.version> property and set the new version number you want to use.
    2. Update the run.sh and run.bat scripts to use the Enterprise edition, this is done by using the enterprise profile in the maven command line: mvn clean install -Pamp-to-war,enterprise. Note. this automatically sets the version to 5.0.1 if you have not explicitly set it.
    3. And as you might have guessed, if you are not using the run script, you will have to remember to always activate the Enterprise profile when running: mvn clean install -Pamp-to-war,enterprise
    4. Install an enterprise license, otherwise the server will be in read-only mode, it goes into the following directory:
      componentX-repo/
      ├── src
      │   ├── main
      │   │   ├── amp 
      │   │   │   ├── config
      │   │   │   │   └── alfresco
      │   │   │   │       ├── extension
      │   │   │   │       │   └── license
      │   │   │   │       │       └── acme-5.0.1-enterprise.lic
      
In this tutorial you have learned how to generate, deploy, and run a project using the Repository AMP archetype.
Parent topic: Creating a project [30]

Creating a Share extension project (AMP)

The Alfresco Share AMP maven archetype can be used to create a new Alfresco Module extension project for the share.war. For more information about this project type see Share AMP Archetype [19]
This task assumes you have completed all instructions in Installing and configuring software [29].
This task shows how you can use the Share AMP archetype of the Alfresco SDK to generate a Share webapp extension module containing a simple Aikau Page and Widget (Aikau is the new Alfresco UI Framework used to build web pages and Dashlets).
  1. Create a suitable directory in which to store all your Maven projects (if you have not already done so), such as alfresco-extensions.
  2. Change into your alfresco-extensions directory.
  3. Run the following command:

    mvn archetype:generate -Dfilter=org.alfresco:       
    Important: As the archetypes are available via Maven Central you do not need to specify a catalog.

    You will be prompted to choose an archetype:

                        
    Choose archetype:
    1: remote -> org.alfresco.maven.archetype:alfresco-allinone-archetype (Sample multi-module project for All-in-One development on the Alfresco plaftorm. Includes modules for: Repository WAR overlay, Repository AMP, Share WAR overlay, Solr configuration, and embedded Tomcat runner)
    2: remote -> org.alfresco.maven.archetype:alfresco-amp-archetype (Sample project with full support for lifecycle and rapid development of Repository AMPs (Alfresco Module Packages))
    3: remote -> org.alfresco.maven.archetype:share-amp-archetype (Share project with full support for lifecycle and rapid development of AMPs (Alfresco Module Packages))
    Choose a number or apply filter (format: [groupId:]artifactId, case sensitive contains): : 
    
  4. Enter 3 to have Maven generate an Alfresco Share Module Package (AMP) project.
  5. You will be prompted to choose an archetype version:

    Choose org.alfresco.maven.archetype:alfresco-amp-archetype version: 
    1: 2.0.0-beta-1
    2: 2.0.0-beta-2
    3: 2.0.0-beta-3
    4: 2.0.0-beta-4
    5: 2.0.0
    6: 2.1.0
    Choose a number: 6: 
                                                

    Press Enter to select the default (which is the most recent version).

  6. You will then be prompted to enter a value for the property groupId:

    Define value for property 'groupId': : com.acme

    Here we have specified com.acme representing the domain for a fictional company acme.com. Specify a groupId matching your company domain.

  7. You will then be prompted to enter a value for the property artifactId:

    Define value for property 'artifactId': : componentX-share

    Here we have specified componentX-share representing an X component with a specific extension for the Alfersco Share UI. Try and name the Share extensions in a way so it is easy to see what kind of extension it is for the share.war application. Here are some example names for share extensions so you get the idea: zip-and-download-action-share, digital-signature-share, business-reporting-share, these share extensions would typically have corresponding Repo extensions if they also include server side business logic as part of the implementation. It is good practice to use the following naming convention for share extensions: {name}-share, where -share indicates that this is an Alfresco Share extension. Note, hyphens are typically used in artifact IDs.

  8. You will then be prompted to enter a value for the property package:

    Define value for property 'package':  com.acme: : com.acme.componentX

    Here we have specified com.acme.componentX representing an X component Java package. This package will be used for any example Java code generated by the archetype. It is good practice to keep all Java code you write under this package so it does not clash with other components/extensions. Any Spring beans generated by this archetype will use this package in the ID.

    Important: Java packages cannot have hyphens in them.
  9. You will then be prompted to enter Y to accept the values you have entered, or n to reject and change. Press Enter to accept the values.

    A new project directory containing a number of sub-directories and support files for the AMP will be created in the directory componentX-share.

  10. Change into the freshly created componentX-share directory and browse the various files and directories to see what has been created.

    The following directory structure has been created for you:

    componentX-share/
    ├── pom.xml (Maven project file)
    ├── run.sh  (Mac/Linux script to have this AMP applied to the Share WAR and run in Tomcat)
    ├── run.bat (Windows script to have this AMP applied to the Share WAR and run in Tomcat)
    ├── src
    │   ├── main
    │   │   ├── amp (For more information about the AMP structure see: https://wiki.alfresco.com/wiki/AMP_Files)
    │   │   │   ├── config
    │   │   │   │   └── alfresco
    │   │   │   │       └── web-extension
    │   │   │   │           ├── custom-slingshot-application-context.xml  (Loads custom.properties)
    │   │   │   │           ├── messages
    │   │   │   │           │   └── custom.properties  (Custom share UI labels, messages etc)
    │   │   │   │           ├── site-data
    │   │   │   │           │   └── extensions
    │   │   │   │           │       └── example-widgets.xml  (Dojo package definitions for the Aikau framework)
    │   │   │   │           └── site-webscripts
    │   │   │   │               ├── com
    │   │   │   │               │   └── example
    │   │   │   │               │           └── pages  
    │   │   │   │               │           ├── simple-page.get.desc.xml  (Simple Aikau page for demonstration purpose)
    │   │   │   │               │           ├── simple-page.get.html.ftl
    │   │   │   │               │           └── simple-page.get.js
    │   │   │   │               └── org
    │   │   │   │                   └── alfresco
    │   │   │   │                       └── README.md
    │   │   │   ├── file-mapping.properties
    │   │   │   ├── module.properties
    │   │   │   └── web
    │   │   │       └── js
    │   │   │           └── example
    │   │   │               └── widgets (Simple Aikau widget for demonstraion purpose)
    │   │   │                   ├── css
    │   │   │                   │   └── TemplateWidget.css
    │   │   │                   ├── i18n
    │   │   │                   │   └── TemplateWidget.properties
    │   │   │                   ├── templates
    │   │   │                   │   └── TemplateWidget.html
    │   │   │                   └── TemplateWidget.js
    │   │   ├── java
    │   │   │   └── com
    │   │   │       └── acme
    │   │   │           └── componentX
    │   │   └── resources
    │   │       └── META-INF
    │   │           ├── resources
    │   │           │   └── test.html
    │   │           └── share-config-custom.xml.sample (Remove .sample to use and keep extension specific stuff in this config)
    │   └── test
    │       ├── java
    │       │   └── com
    │       │       └── acme
    │       │           └── componentX
    │       ├── properties
    │       └── resources
    │           ├── alfresco
    │           │   └── web-extension
    │           │       └── share-config-custom.xml (Configures where the Repository is running)
    │           └── log4j.properties
    └── tomcat
        └── context.xml (Virtual Webapp context for RAD development)
    
  11. At this point, before you have made any changes, you can build the project by typing:

    mvn install
    Important: Maven will ensure that all requirements are downloaded. This make take some time.

    The project will return with the message BUILD SUCCESS. You should see the AMP artifact installed in your local repository .m2/repository/com/acme/componentX-share/1.0-SNAPSHOT/componentX-share-1.0-SNAPSHOT.amp

  12. Run and Test the sample Aikau Page

    Important: For this to work you will need to have the Alfresco WAR running in another Tomcat (8080). You can quite easily achieve this by generating a repo-amp project and running it, see Repository AMP Project [58].
    To test the custom Share page you will need to start an embedded Tomcat (8081) and deploy the Share WAR with the componentX-share AMP applied. This can be done in two ways:
    1. With mvn clean install -Pamp-to-war
    2. Via the run.sh script (or run.bat on Windows), which does the same thing, plus making sure Spring Loaded library is available.

    Let's start Tomcat via the script as follows (use run.bat on Windows):

    ./run.sh
    ...
    Apr 30, 2015 11:40:42 AM org.apache.catalina.core.ApplicationContext log
    INFO: org.tuckey.web.filters.urlrewrite.UrlRewriteFilter INFO: loaded (conf ok)
    Apr 30, 2015 11:40:42 AM org.apache.catalina.core.ApplicationContext log
    INFO: Initializing Spring FrameworkServlet 'Spring Surf Dispatcher Servlet'
    Apr 30, 2015 11:40:42 AM org.apache.coyote.AbstractProtocol start
    INFO: Starting ProtocolHandler ["http-bio-8081"]
    
    Important: You may first need to make the shell script executable using the command chmod +x run.sh.
  13. Once the web application has started (it may take a little while), point your browser at http://localhost:8081/share/page/hdp/ws/simple-page to test the sample Page. The page should return the following Title: This is a simple page and a Hello World widget with the text: Hello from i18n!
  14. If you are prompted to login, then use username admin and a password admin.
  15. Configure Enterprise Edition (Optional)

    So far we have used the project with its default configuration, which is using Alfresco Community edition 5.0.d. If you are going to work with the Enterprise edition then you need to do the following:

    • Decide what Enterprise version you will be using, if you are going to use version 5.0.1 then you are set as that is the default Enterprise version. If you want to use another version then open up the componentX-share/pom.xml file and uncomment the <alfresco.version>5.0.d</alfresco.version> property and set the new version number you want to use.
    • Update the run.sh and run.bat scripts to use the Enterprise edition, this is done by using the enterprise profile in the maven command line: mvn clean install -Pamp-to-war,enterprise. Note. this automatically sets the version to 5.0.1 if you have not explicitly set it.
    • And as you might have guessed, if you are not using the run script, you will have to remember to always activate the Enterprise profile when running: mvn clean install -Pamp-to-war,enterprise
In this tutorial you have learned how to generate, deploy, and run a project using the Share AMP archetype.
Parent topic: Creating a project [30]

Creating an All-in-One (AIO) project (WARs)

The All-in-One maven archetype can be used to create a new multi-module project that will produce customized alfresco.war and share.war artifacts. For more information about this project type see All-in-One Archetype [20]
This task assumes you have completed all instructions in Installing and configuring [29].
This task shows how you can use the All-in-One archetype of the Alfresco SDK to generate a multi module extension project containing repo-amp, share-amp, and WAR projects.
  1. Create a suitable directory in which to store all your Maven projects (if you have not already done so), such as alfresco-extensions.
  2. Change into your alfresco-extensions directory.
  3. Run the following command:

    mvn archetype:generate -Dfilter=org.alfresco:       
    Important: As the archetypes are available via Maven Central you do not need to specify a catalog.

    You will be prompted to choose an archetype:

                        
    Choose archetype:
    1: remote -> org.alfresco.maven.archetype:alfresco-allinone-archetype (Sample multi-module project for All-in-One development on the Alfresco plaftorm. Includes modules for: Repository WAR overlay, Repository AMP, Share WAR overlay, Solr configuration, and embedded Tomcat runner)
    2: remote -> org.alfresco.maven.archetype:alfresco-amp-archetype (Sample project with full support for lifecycle and rapid development of Repository AMPs (Alfresco Module Packages))
    3: remote -> org.alfresco.maven.archetype:share-amp-archetype (Share project with full support for lifecycle and rapid development of AMPs (Alfresco Module Packages))
    Choose a number or apply filter (format: [groupId:]artifactId, case sensitive contains): : 
    
  4. Enter 1 to have Maven generate an Alfresco All-in-One project.
  5. You will be prompted to choose an archetype version:

    Choose org.alfresco.maven.archetype:alfresco-amp-archetype version: 
    1: 2.0.0-beta-1
    2: 2.0.0-beta-2
    3: 2.0.0-beta-3
    4: 2.0.0-beta-4
    5: 2.0.0
    6: 2.1.0
    Choose a number: 6: 
                                                

    Press Enter to select the default (which is the most recent version).

  6. You will then be prompted to enter a value for the property groupId:

    Define value for property 'groupId': : com.acme

    Here we have specified com.acme representing the domain for a fictional company acme.com. Specify a groupId matching your company domain.

  7. You will then be prompted to enter a value for the property artifactId:

    Define value for property 'artifactId': : acme-cms-poc

    Here we have specified acme-cms-poc representing a Proof-of-Concept (PoC) Content Management System (CMS) project to validate Alfresco as a perfect fit. Try and name the All-in-One projects so it is easy to know what they contain/represent. The naming should represent complete projects in contrast to specific AMP extensions that just implements a specific functionality in a larger solution. Note, hyphens are typically used in artifact IDs.

  8. You will then be prompted to enter a value for the property package:

    Define value for property 'package':  com.acme: : com.acme.cmspoc

    Here we have specified com.acme.cmspoc representing the top Java package for this project. This package will be used for any example Java code generated by the archetype. It is good practice to keep all Java code you write under this package so it does not clash with other projects. Any Spring beans generated by this archetype will use this package in the ID.

    Important: Java packages cannot have hyphens in them.
  9. You will then be prompted to enter Y to accept the values you have entered, or n to reject and change. Press Enter to accept the values.

    A new project directory containing a number of sub-directories and support files for the project will be created in the directory acme-cms-poc.

  10. Change into the freshly created acme-cms-poc directory and browse the various files and directories to see what has been created.

    The following directory structure has been created for you:

    acme-cms-poc/
    ├── pom.xml (Maven project file)
    ├── run.sh  (Mac/Linux script to run customized Alfresc WAR and Share WAR together with Solr4 in Tomcat)
    ├── run.bat (Windows script to run customized Alfresc WAR and Share WAR together with Solr4 in Tomcat)
    ├── repo  (This is the Alfresco WAR project - produces a customized Alfresco.WAR by applying the AMP produced by the /repo-amp project) 
    │   ├── pom.xml
    │   └── src
    │       └── main
    │           ├── properties
    │           │   └── local
    │           │       └── alfresco-global.properties
    │           └── resources
    │               └── alfresco
    │                   └── extension
    │                       └── dev-log4j.properties
    ├── repo-amp  (This is a standard Repository AMP extions project - produces a Repository AMP)
    │   ├── pom.xml
    │   └── src
    │       ├── main
    │       │   ├── amp  (For more information about the AMP structure see: https://wiki.alfresco.com/wiki/AMP_Files)
    │       │   │   ├── config
    │       │   │   │   └── alfresco
    │       │   │   │       ├── extension
    │       │   │   │       │   └── templates
    │       │   │   │       │       └── webscripts  (Your Web Scripts should go under this directory)
    │       │   │   │       │           ├── webscript.get.desc.xml  (Sample Web Script that you can try out)
    │       │   │   │       │           ├── webscript.get.html.ftl
    │       │   │   │       │           └── webscript.get.js
    │       │   │   │       └── module
    │       │   │   │           └── repo-amp  (AMP Module ID)
    │       │   │   │               ├── alfresco-global.properties (Put default values for properties specific to this extension here)
    │       │   │   │               ├── context
    │       │   │   │               │   ├── bootstrap-context.xml  (Bootstrapping of content models, content, i18n files etc)
    │       │   │   │               │   └── service-context.xml  (Your service beans go here)
    │       │   │   │               ├── model
    │       │   │   │               │   ├── content-model.xml   (Content model for your files)
    │       │   │   │               │   └── workflow-model.xml  (Content model for workflow implementations)
    │       │   │   │               └── module-context.xml  (Spring context file that is picked up by Alfresco)
    │       │   │   ├── module.properties  (AMP module ID, Version etc)
    │       │   │   └── web  (If your AMP has some UI the files would go here, unlikely now when the Alfresco Explorer UI is gone)
    │       │   │       ├── css
    │       │   │       │   └── demoamp.css
    │       │   │       ├── jsp
    │       │   │       │   └── demoamp.jsp
    │       │   │       ├── licenses
    │       │   │       │   └── README-licenses.txt
    │       │   │       └── scripts
    │       │   │           └── demoamp.js
    │       │   └── java  (Your Java classes go here, this is where most of the module extension implementation code would go, you can remove the demo component)
    │       │       └── com
    │       │           └── acme
    │       │               └── cmspoc
    │       │                   └── demoamp  (Demo module component, can be removed)
    │       │                       ├── DemoComponent.java
    │       │                       └── Demo.java
    │       └── test
    │           ├── java
    │           │   └── com
    │           │       └── acme
    │           │           └── cmspoc
    │           │               └── demoamp
    │           │                   └── test  (Example test of the demo component, can be removed)
    │           │                       └── DemoComponentTest.java
    │           ├── properties
    │           │   └── local
    │           │       └── alfresco-global.properties  (environment specific configuration, the local env is active by default)
    │           └── resources
    │               ├── alfresco
    │               │   └── extension
    │               │       └── disable-webscript-caching-context.xml  (file to disable server side JavaScript compilation to Java code)
    │               └── test-log4j.properties
    ├── runner (Tomcat Runner that deploys the WARs produced by the /repo and /share projects, the Solr4 webapp is deployed directly from maven repo)
    │   ├── pom.xml
    │   ├── src
    │   │   └── main
    │   │       └── webapp
    │   │           └── index.html
    │   └── tomcat   (Virtual Webapp contexts for RAD development)
    │       ├── context-repo.xml
    │       ├── context-share.xml
    │       └── context-solr.xml
    ├── run.sh
    ├── share (This is the Share WAR project - produces a customized Share.WAR by applying the AMP produced by the /share-amp project)
    │   ├── pom.xml
    │   └── src
    │       └── main
    │           └── resources
    │               ├── alfresco
    │               │   └── web-extension
    │               │       ├── custom-slingshot-application-context.xml.sample
    │               │       └── share-config-custom.xml.sample
    │               └── log4j.properties
    ├── share-amp  (This is a standard Share AMP extions project - produces a Share AMP)
    │   ├── pom.xml
    │   └── src
    │       ├── main
    │       │   ├── amp  (For more information about the AMP structure see: https://wiki.alfresco.com/wiki/AMP_Files)
    │       │   │   ├── config
    │       │   │   │   └── alfresco
    │       │   │   │       └── web-extension
    │       │   │   │           ├── custom-slingshot-application-context.xml  (Loads the custom.properties file)
    │       │   │   │           ├── messages
    │       │   │   │           │   └── custom.properties  (Custom share UI labels, messages etc)
    │       │   │   │           ├── site-data
    │       │   │   │           │   └── extensions
    │       │   │   │           │       └── example-widgets.xml  (Dojo package definitions for the Aikau framework)
    │       │   │   │           └── site-webscripts
    │       │   │   │               ├── com
    │       │   │   │               │   └── example
    │       │   │   │               │       └── pages
    │       │   │   │               │           ├── simple-page.get.desc.xml  (Simple Aikau page for demonstration purpose)
    │       │   │   │               │           ├── simple-page.get.html.ftl
    │       │   │   │               │           └── simple-page.get.js
    │       │   │   │               └── org
    │       │   │   │                   └── alfresco
    │       │   │   │                       └── README.md
    │       │   │   ├── file-mapping.properties
    │       │   │   ├── module.properties
    │       │   │   └── web
    │       │   │       └── js
    │       │   │           └── example
    │       │   │               └── widgets   (Simple Aikau widget for demonstration purpose)
    │       │   │                   ├── css
    │       │   │                   │   └── TemplateWidget.css
    │       │   │                   ├── i18n
    │       │   │                   │   └── TemplateWidget.properties
    │       │   │                   ├── templates
    │       │   │                   │   └── TemplateWidget.html
    │       │   │                   └── TemplateWidget.js
    │       │   ├── java
    │       │   │   └── com
    │       │   │       └── acme
    │       │   │           └── cmspoc
    │       │   └── resources
    │       │       └── META-INF
    │       │           └── share-config-custom.xml.sample
    │       └── test
    │           ├── java
    │           │   └── com
    │           │       └── acme
    │           │           └── cmspoc
    │           │               └── demoamp  (Example of how to use Alfresco Share Page Objects (PO) to create functional tests for your UI customizations)
    │           │                   ├── DemoPageTestIT.java
    │           │                   └── po
    │           │                       └── DemoPage.java
    │           └── resources
    │               └── testng.xml
    └── solr-config  (Loads the configuration files necessary for running Apache Solr4)
        └── pom.xml
    
  11. At this point, before you have made any changes, you can build the project by typing:

    mvn install
    Note: Maven will ensure that all requirements are downloaded. This make take some time.

    As the builds goes on you will se the following artifacts built and installed in your local repository:

    • .m2/repository/com/acme/repo-amp/1.0-SNAPSHOT/repo-amp-1.0-SNAPSHOT.amp
    • .m2/repository/com/acme/share-amp/1.0-SNAPSHOT/share-amp-1.0-SNAPSHOT.amp
    • .m2/repository/com/acme/repo/1.0-SNAPSHOT/repo-1.0-SNAPSHOT.war, contains the repo-amp-1.0-SNAPSHOT.amp
    • .m2/repository/com/acme/share/1.0-SNAPSHOT/share-1.0-SNAPSHOT.war, contains the share-amp-1.0-SNAPSHOT.amp

    The project will return with the message BUILD SUCCESS.

  12. You can build, load RAD requirements, and run your project by typing:

    
    ./run.sh                        
                            
                        
    Important: You may first need to make the shell script executable using the command chmod +x run.sh.
  13. Direct your web browser to:

    http://localhost:8080/share

    You can log in using a user name of admin and a password of admin.

  14. Configure Enterprise Edition (Optional)

    So far we have used the project with its default configuration, which is using Alfresco Community edition 5.0.d. If you are going to work with the Enterprise edition then you need to do the following:

    1. Decide what Enterprise version you will be using, if you are going to use version 5.0.1 then you are set as that is the default Enterprise version. If you want to use another version then open up the acme-cms-poc/pom.xml file and uncomment the <alfresco.version>5.0.d</alfresco.version> property and set the new version number you want to use.
    2. Update the run.sh and run.bat scripts to use the Enterprise edition, this is done by using the enterprise profile in the maven command line: mvn clean install -Prun,enterprise. Note. this automatically sets the version to 5.0.1 if you have not explicitly set it.
    3. And as you might have guessed, if you are not using the run script, you will have to remember to always activate the Enterprise profile when running: mvn clean install -Prun,enterprise
    4. Install an enterprise license, otherwise the server will be in read-only mode. It goes into the following directory:
      acme-cms-poc/
      ├── repo   
      │   ├── pom.xml
      │   └── src
      │       └── main
      │           ├── properties
      │           └── resources
      │               └── alfresco
      │                   └── extension
      │   │   │   │       │   └── license
      │   │   │   │       │       └── acme-5.0.1-enterprise.lic
      

    If the license is properly installed you should see logs as follows when the server starts:

    ...
    2015-05-08 09:52:21,359  INFO  [enterprise.license.AlfrescoLicenseManager] [localhost-startStop-1] Successfully installed license from file [/home/martin/src/alfresco-extensions/acme-cms-poc/runner/target/tomcat/webapps/repo/WEB-INF/classes/alfresco/extension/license/Enterprise-5.0.lic]
    ...
    2015-05-08 09:52:23,614  INFO  [service.descriptor.DescriptorService] [localhost-startStop-1] Alfresco started (Enterprise). Current version: 5.0.1 (r100823-b68) schema 8,022. Originally installed version: 5.0.0 (d r99759-b2) schema 8,022.
    ...
    
In this tutorial you have learned how to generate, deploy, and run a project using the All-in-One (AIO) archetype.
Parent topic: Creating a project [30]

Maven Archetypes - Command Reference

There are three Maven archetypes on which the Alfresco SDK can base the generation of projects. This section contains the Maven command reference for these projects.
For more information about the archetypes see:
  • Repository AMP archetype [22]
  • All-In-One (AIO) archetype [53]
  • Share AMP archetype [21]
  • Repository AMP archetype command reference [59] This describes the scripts and Maven commands that can be used on an Alfresco Repository extension project based on the Repository AMP archetype.
  • Share AMP archetype command reference [60] This describes the scripts and Maven commands that can be used on an Alfresco Share extension project based on the Share AMP archetype.
  • All-in-One (AIO) archetype command reference [61] This describes the scripts and Maven commands that can be used on an Alfresco All-in-One (AIO) extension project based on the AIO archetype.
Parent topic: Alfresco SDK 2.1 [14]

Repository AMP archetype command reference

This describes the scripts and Maven commands that can be used on an Alfresco Repository extension project based on the Repository AMP archetype.

Scripts and commands:

Command Description
./run.sh and run.bat Linux/Mac and Windows scripts for running an embedded Tomcat with the customized alfresco.war (that is, with the Repo AMP applied) and the flat file database H2. Access to Alfresco UI is via http://localhost:8080/alfresco. The username/password is admin/admin. This script will also configure JVM memory and automatically setup Spring Loaded for hot reloading of classes (it basically sets up MAVEN_OPTS for you). See inside the script for further details.
Warning: This script assumes that you are developing for the Alfresco Community Edition. If you use an Enterprise Edition you need to update the maven command in this script so it uses the enterprise profile: mvn integration-test -Pamp-to-war,enterprise.
mvn compile alfresco:refresh-repo Compiles the source code and puts the class files and resources under /target. Then makes a POST call to the Alfresco Repository web application (alfresco.war) to refresh the web script container. So any changes that were made to web scripts should be visible after a page refresh.
Note: This command is typically used together with the run.sh/bat script for Rapid Application Development (RAD). The RAD process can be described like this:
  1. Start Tomcat with current alfresco.war customization (run.sh/bat) in console window one.
  2. From an editor, change some files (classes, web scripts, and so on).
  3. Execute this cmd (mvn compile alfresco:refresh-repo) from console window two.
  4. Refresh the page/web script that you are working on.
  5. Done? No -> Go back to step 2 and start over.
  6. Finished with implementation.
mvn package Runs unit tests and packages AMP in ${project.build.directory}/${project.build.finalName}.amp.
mvn install Like mvn package but also installs AMP in local Maven repository to be depended upon.
mvn test Runs unit tests.
mvn install -DskipTests=true Like mvn install but skips unit tests.
mvn install -Pamp-to-war Like run.sh or run.bat but does not configure JVM memory and Spring Loaded if you have not configured it in MAVEN_OPTS. See set up MAVEN_OPTS [38]. If you use the Enterprise edition see the next command.
mvn install -Pamp-to-war,enterprise Like mvn install -Pamp-to-war but uses Enterprise artifacts. Note you need to have set up access to the private repository [51] containing the Enterprise artifacts.
mvn clean -Ppurge Removes H2 database (with metadata), alf_data (with content files and index files), and log files. Useful to purge the development repo (by default self contained in ${project.basedir}/alf_data_dev.
Note: This is an important command to use if you change significant settings in your project. For example, if you change the Alfresco edition from Community to Enterprise. It is important to purge databases and other data that might otherwise be persisted.
Parent topic: Maven Archetypes - Command Reference [8]

Share AMP archetype command reference

This describes the scripts and Maven commands that can be used on an Alfresco Share extension project based on the Share AMP archetype.

Scripts and commands:

Command Description
./run.sh and run.bat Linux/Mac and Windows scripts for running an embedded Tomcat with the customized share.war (that is, with the Share AMP applied). Access to Alfresco Share UI is via http://localhost:8081/share. The username/password is admin/admin. This script will also configure JVM memory and automatically setup Spring Loaded for hot reloading of classes (it basically sets up MAVEN_OPTS for you). See inside script for further details.
Warning: This script assumes that you are developing for the Alfresco Community Edition. If you use an Enterprise Edition you need to update the maven command in this script so it uses the enterprise profile: mvn integration-test -Pamp-to-war,enterprise.
Warning: This script also assumes that another Tomcat is running locally on port 8080 with the Alfresco Repository (alfresco.war) web application deployed.
mvn compile alfresco:refresh-share Compiles the source code and puts the class files and resources under /target. Then makes POST calls to the Alfresco Share web application (share.war) to refresh the Spring Surf web script container and clear dependency caches. So any changes that was made to web scripts, Aikau pages, Aikau Widgets, Dashlets, and so on, should be visible after a page refresh.
Note: This command is typically used together with the run.sh/bat script for Rapid Application Development (RAD). The RAD process can be described like this:
  1. Start Tomcat with current share.war customization (run.sh/bat) in console window one.
  2. From an editor change some files (classes, pages, widgets, and so on)
  3. Execute this cmd (mvn compile alfresco:refresh-share) from console window two.
  4. Refresh the page/web script you are working on.
  5. Done? No -> Go back to step 2 and start over.
  6. Finished with implementation.
mvn package Runs unit tests and packages AMP in ${project.build.directory}/${project.build.finalName}.amp.
mvn install Like mvn package but also installs AMP in local Maven repository to be depended upon.
mvn test Runs unit tests.
mvn install -DskipTests=true Like mvn install but skips unit tests.
mvn install -Pamp-to-war Like run.sh or run.bat but does not configure JVM memory and Spring Loaded if you have not configured it in MAVEN_OPTS. See set up MAVEN_OPTS [38]. If you use the Enterprise edition see next command.
mvn install -Pamp-to-war,enterprise Like mvn install -Pamp-to-war but uses Enterprise artifacts. Note you need to have set up access to the private repository [51] containing the Enterprise artifacts.
Parent topic: Maven Archetypes - Command Reference [8]

All-in-One (AIO) archetype command reference

This describes the scripts and Maven commands that can be used on an Alfresco All-in-One (AIO) extension project based on the AIO archetype.

The All-in-One Alfresco project contains the following modules:

  • repo-amp: A Repository AMP project, demonstrating sample project structure and demo component loading.
  • repo: An alfresco.war aggregator project, overlaying the standard Alfresco WAR with the repo-amp and any other AMPs and JARs that have been included as dependencies and configured in the overlay
  • share-amp: A Share AMP project, demonstrating sample project structure and demo Aikau page
  • share: A share.war aggregator project, overlaying the standard Share WAR with the share-amp and any other AMPs and JARs that have been included as dependencies and configured in the overlay
  • solr-config: Brings in the Apache Solr4 configuration files
  • runner: A Tomcat + H2 runner, capable of running the custom alfresco.war, custom share.war, and solr4.war in embedded mode for demo/integration-testing purposes

Scripts and commands:

Command Description
./run.sh and run.bat Linux/Mac and Windows scripts for running an embedded Tomcat with the customized alfresco.war (repo-amp applied), custom share.war (share-amp applied), and solr4.war. Access to Alfresco Share UI is via http://localhost:8080/share. Username/pwd is admin/admin. This script will also configure JVM memory and automatically setup Spring Loaded for hot reloading of classes (it basically sets up MAVEN_OPTS for you). See inside script for further details.
Warning: This script assumes that you are developing for the Alfresco Community edition. If you use an Enterprise Edition you need to update the maven command in this script so it uses the 'enterprise' profile: mvn install -Prun,enterprise.
repo-amp/mvn compile alfresco:refresh-repo Compiles the source code for the Repository AMP and puts the class files and resources under repo-amp/target. Then makes a POST call to the Alfresco Repository web application (alfresco.war) to refresh the web script container. So any changes that was made to Web scripts should be visible after a page refresh.
Note: This command is typically used together with the run.sh/bat script for Rapid Application Development (RAD). The RAD process can be described like this:
  1. Start Tomcat with current alfresco.war customization (that is, run.sh/bat) in console window one.
  2. From an editor change some files (classes, web scripts, and so on) for the Repository AMP.
  3. Execute this cmd (that is, mvn repo-amp/compile alfresco:refresh-repo) from console window two.
  4. Refresh the page / web script you are working on.
  5. Done? No -> Go back to step 2 and start over.
  6. Finished with implementation.
share-amp/mvn compile alfresco:refresh-share Compiles the source code for the Share AMP and puts the class files and resources under share-amp/target. Then makes POST calls to the Alfresco Share web application (share.war) to refresh the Spring Surf web script container and clear dependency caches. So any changes that was made to web scripts, Aikau pages, Aikau widgets, dashlets, and so on, should be visible after a page refresh.
Note: This command is typically used together with the run.sh/bat script for Rapid Application Development (RAD). The RAD process can be described like this:
  1. Start Tomcat with current share.war customization (that is, run.sh/bat) in console window one.
  2. From an editor change some files (classes, pages, widgets, and so on) for the Share AMP.
  3. Execute this cmd (that is, share-amp/mvn compile alfresco:refresh-share) from console window two.
  4. Refresh the page / web script you are working on.
  5. Done? No -> Go back to step 2 and start over.
  6. Finished with implementation.
mvn package Runs unit tests and packages modules in their respective target directories, for example:
  • all-in-one/repo-amp/target/1.0-SNAPSHOT/repo-amp-1.0-SNAPSHOT.amp
  • all-in-one/share-amp/target/1.0-SNAPSHOT/share-amp-1.0-SNAPSHOT.amp
  • all-in-one/repo/target/1.0-SNAPSHOT/repo-1.0-SNAPSHOT.war, contains repo-amp-1.0-SNAPSHOT.amp from local maven repo (not the just packed version)
  • all-in-one/share/target/1.0-SNAPSHOT/share-1.0-SNAPSHOT.war, contains share-amp-1.0-SNAPSHOT.amp from local maven repo (not the just packed version)
Note: This does not apply these newly packaged AMPs to their respective WARs, use mvn install for that.
mvn install Like mvn package but also installs artifacts in local Maven repository, for example:
  • .m2/repository/com/acme/repo-amp/1.0-SNAPSHOT/repo-amp-1.0-SNAPSHOT.amp
  • .m2/repository/com/acme/share-amp/1.0-SNAPSHOT/share-amp-1.0-SNAPSHOT.amp
  • .m2/repository/com/acme/repo/1.0-SNAPSHOT/repo-1.0-SNAPSHOT.war, contains the repo-amp-1.0-SNAPSHOT.amp
  • .m2/repository/com/acme/share/1.0-SNAPSHOT/share-1.0-SNAPSHOT.war, contains the share-amp-1.0-SNAPSHOT.amp
Where these artifacts can be accessed by other local projects that depend on them.
mvn install -DskipTests=true Like mvn install but skips unit tests.
mvn install -Prun Like run.sh or run.bat but does not configure JVM memory and Spring Loaded if you have not configured it in MAVEN_OPTS, see set up MAVEN_OPTS [38]. If you use the Enterprise edition, see the next command.
mvn install -Prun,enterprise Like mvn install -Prun but uses Enterprise artifacts. Note you need to have set up access to the private repository [51] containing the Enterprise artifacts.
mvn clean install -Prun,regression-testing Runs regression testing of the Alfresco Share UI (share.war). Uses the Alfresco internal Selenium Page Object (PO) based tests. This is very useful when you have developed a lot of customizations for the Share UI and you want to make sure you have not broken any standard Share UI functionality. Typically run this from a CI server (or better a Selenium-Grid) to test for regression of the standard Alfresco Share UI.
Important: The Selenium WebDriver is configured to use FireFox (FF) by default, so you need to have FF installed for the regression tests to be able to run. Use version 35 or newer.
Important: It is also highly recommended that the workstation that is running the regression tests is not being worked on at the same time as the tests are running, as that can affect the outcome of the tests.
Warning: This command assumes that you are developing for the Alfresco Community Edition. If you use an Enterprise Edition you need to update the maven command so it uses the 'enterprise' profile and the Enterprise share-po library: mvn clean install -Prun,enterprise,regression-testing. Also, make sure that you have installed an enterprise license in the repo project, otherwise the system will be in read-only mode and loads of tests will not pass.
mvn clean install -Prun,functional-testing Runs functional testing of the Alfresco Share UI customizations that you have developed, such as pages and Dashlets. For information about how to write these tests, see the example test called share-amp/src/test/java/{package-path}/demoamp/DemoPageTestIT and its Page Object class called share-amp/src/test/java/{package-path}/demoamp/po/DemoPage.java.
Important: The Selenium WebDriver is configured to use FireFox (FF) by default, so you need to have FF installed for the functional tests to be able to run. Use version 35 or newer.
Important: It is also highly recommended that the workstation that is running the functional tests is not being worked on at the same time as the tests are running, as that can affect the outcome of the tests.
Warning: This command assumes that you are developing for the Alfresco Community Edition. If you use an Enterprise Edition you need to update the maven command so it uses the 'enterprise' profile and the Enterprise share-po library: mvn clean install -Prun,enterprise,functional-testing.
mvn clean -Ppurge Removes H2 database (with metadata), alf_data (with content files and index files), and log files. Useful to purge the development repo (by default self contained in ${project.basedir}/alf_data_dev.
Note: This is an important command to use if you change significant settings in your project. For example, if you change the Alfresco Edition from Community to Enterprise. It is important to purge databases and other data that might otherwise be persisted.
Parent topic: Maven Archetypes - Command Reference [8]

Rapid Application Development (RAD)

These tutorials cover how to employ the RAD features of the Alfresco SDK.

Rapid Application Development (RAD) and Test Driven Development (TDD) are big goals for the Alfresco SDK. The SDK is designed to support the hot reloading of code (via Spring Loaded) so that you can modify JavaScript, FreeMarker and Java code, and have the changes take effect without having to click the Refresh Web Scripts button, restart Alfresco Tomcat, or restart anything else.

For example, in your SDK project, you can change test code, re-run your test, and the results will be displayed immediately. This allows for Test Driven Development (TDD).

The hot reloading above all saves you time as a developer. No more waiting around for Alfresco Tomcat restarts to see your code changes take effect.

Important: It is assumed that you will work through the tutorials in this section in the order in which they are presented.
  • Importing SDK projects into Eclipse [62] The Alfresco SDK is designed to work well with Eclipse. This support includes the ability to import existing SDK projects (created via the command line) into Eclipse.
  • Rapid Application Development in Eclipse (Hot reloading) [63] Hot reloading is the ability to modify your application's code, and view the changes without having to restart Alfresco Tomcat. This allows for significant savings in development time that would otherwise be wasted restarting Tomcat. Hot reloading is the key to enabling Rapid Application Development (RAD) and Test Driven Development (TDD).
  • Importing SDK projects into IntelliJ IDEA [64] The Alfresco SDK is designed to work well with IntelliJ IDEA. This support includes the ability to import existing SDK projects (created via the command line) into IDEA.
  • Rapid Application Development in IntelliJ IDEA (Hot reloading) [65] Hot reloading is the ability to modify your application's code, and view the changes without having to restart Alfresco Tomcat. This allows for significant savings in development time that would otherwise be wasted restarting Tomcat. Hot reloading is the key to enabling Rapid Application Development (RAD) and Test Driven Development (TDD).
  • Remote debugging with an IDE [66] It is possible to start an application ready for remote debugging by using the Maven mvnDebug command.
Parent topic: Alfresco SDK 2.1 [14]

Importing SDK projects into Eclipse

The Alfresco SDK is designed to work well with Eclipse. This support includes the ability to import existing SDK projects (created via the command line) into Eclipse.
This task assumes you completed the Installing and Configuring software [29] section and generated a project as described in this section [30].
You will learn how to import an existing Maven project into Eclipse.
  1. In Eclipse, from the main menu select File > Import... > Maven > Existing Maven Projects.
  2. Click Next >
  3. Click Browse...>
  4. Navigate to the directory where your Maven project is located. For example alfresco-extensions/all-in-one.

    You should see a dialog looking something like this when importing an All-in-One (AIO) project:

  5. Click Finish

    The project, and any sub-projects, will now be imported.

  6. Enable Alfresco Enterprise edition (Optional)

    If your project is using the Enterprise edition of Alfresco you also want Eclipse to load the enterprise versions of the Alfresco WARs and related libraries. You can do this by enable the enterprise profile. In the Package Explorer view to the left, right click on the all-in-one project, then select Maven from the popup menu. Now in the next popup menu choose Select Maven Profiles.... In the dialog that appears select the enterprise profile, you should see a dialog looking something like this now:

You have seen how to import your SDK project(s) into Eclipse. You can now build, run and debug them in the usual way, using RAD and TDD techniques.
Parent topic: Rapid Application Development (RAD) [9]

Rapid Application Development in Eclipse (Hot reloading)

Hot reloading is the ability to modify your application's code, and view the changes without having to restart Alfresco Tomcat. This allows for significant savings in development time that would otherwise be wasted restarting Tomcat. Hot reloading is the key to enabling Rapid Application Development (RAD) and Test Driven Development (TDD).
You should have an extension project imported, see importing a project into Eclipse [67].
In this tutorial you will see how changes to your code can be carried out without having to restart Alfresco Tomcat. This tutorial demonstrates hot reloading of JavaScript, FreeMarker template, and Java code. There are three components that work together to enable the best RAD experience:
  1. Spring Loaded: takes care of hot-reloading any Java class files that we have changed.
  2. Refresh Repository Script: This is a script that will POST a request to the Alfresco Repository Web Application (i.e. alfresco.war) telling it to refresh the Repo Web Script container, so any changes to files related to Web Scripts will be picked up.
  3. Refresh Share Script: This is a script that will POST a request to the Alfresco Share Web Application (i.e. share.war) telling it to refresh the Surf Web Script container, so any changes to files related to Surf Web Scripts will be picked up. This script will also clear the resource dependency caches, so JS changes etc are picked up.

Start an instance of Alfresco Tomcat that will be used for hot-reloading.

  1. Use the run script to start the Application server with the Alfresco extension project deployed, for example:

    
    alfresco-extensions/all-in-one$ ./run.sh                        
                            
                        
    Attention: This is usually done outside the IDE.
  2. Test the custom Repository Web Script

    The All-in-One project (and the Repository AMP project) have a sample Web Script included. You can invoke it by pointing your web browser at http://localhost:8080/alfresco/service/sample/helloworld. If you need to login then use admin with password admin. Running this Web Script produces the output "Message: Hello World from JS! HelloFromJava".

  3. Test the custom Share Aikau Page

    The All-in-One project (and the Share AMP project) have a sample Aikau page included. You can display it by pointing your web browser at http://localhost:8080/share/page/hdp/ws/simple-page. If you need to login then use admin with password admin. The page should display as follows:

Enabling Rapid Application Development (RAD) in Eclipse.

  1. This is enabled by default and there is no specific configuration needed. If you want to have more control over when web applications are refreshed, then see the last tutorial about Run Configurations.

Testing RAD when doing Repository customizations (alfresco.war).

  1. In the Package Explorer, navigate to and expand the all-in-one/repo-amp/src/main/amp/config/alfresco/extension/templates/webscripts folder
  2. Locate the helloworld.get.js file and load it into the editor by double-clicking it.

    This is the controller for the Web Script that we tried after starting the server. Update the controller code by adding an 'UPDATED' string as follows:

    model["fromJS"] = "Hello World from JS! UPDATED";
                            
  3. Now build(Make) the project by saving, i.e. click Ctrl+S

    The application server log should display messages about the web scripts being refreshed:

    2015-05-12 11:13:40,652  INFO  [extensions.webscripts.DeclarativeRegistry] [http-bio-8080-exec-9] Registered 407 Web Scripts (+0 failed), 549 URLs
     2015-05-12 11:13:40,653  INFO  [extensions.webscripts.DeclarativeRegistry] [http-bio-8080-exec-9] Registered 1 Package Description Documents (+0 failed) 
     2015-05-12 11:13:40,653  INFO  [extensions.webscripts.DeclarativeRegistry] [http-bio-8080-exec-9] Registered 0 Schema Description Documents (+0 failed) 
     2015-05-12 11:13:40,656  INFO  [extensions.webscripts.AbstractRuntimeContainer] [http-bio-8080-exec-9] Initialised Repository Web Script Container (in 2215.1865ms)
     2015-05-12 11:13:42,414  INFO  [extensions.webscripts.DeclarativeRegistry] [asynchronouslyRefreshedCacheThreadPool1] Registered 407 Web Scripts (+0 failed), 549 URLs
     2015-05-12 11:13:42,414  INFO  [extensions.webscripts.DeclarativeRegistry] [asynchronouslyRefreshedCacheThreadPool1] Registered 1 Package Description Documents (+0 failed) 
     2015-05-12 11:13:42,414  INFO  [extensions.webscripts.DeclarativeRegistry] [asynchronouslyRefreshedCacheThreadPool1] Registered 0 Schema Description Documents (+0 failed) 
                            
    Note that there is no output in the Eclipse console, or other window. Also, it is only the Repository Application (i.e. alfresco.war) that is being refreshed, the Share application is not touched.
  4. Refresh the http://localhost:8080/alfresco/service/sample/helloworld Repository Web Script page from the Browser

    The output from the Web Script should change to "Message: Hello World from JS! UPDATED HelloFromJava". Note that there is no need to restart the application server, just a Make of the project, and a refresh of the Web Script page from the browser (you are basically invoking the Web Script again and the update should be immediately visible).

  5. Now locate the helloworld.get.html.ftl file and load it into the editor by double-clicking it.

    This is the FreeMarker template for the Web Script. Update the template by adding an 'ExtraTemplateText' string as follows:

    Message: ${fromJS} ${fromJava} ExtraTemplateText                       
                            
  6. Now build(Make) the project by clicking Ctrl+S

    The application server log should display messages about the web scripts being refreshed.

  7. Refresh the http://localhost:8080/alfresco/service/sample/helloworld Repository Web Script page from the Browser

    The output from the Web Script should change to "Message: Hello World from JS! UPDATED HelloFromJava ExtraTemplateText ". Again, note that there is no need to restart the application server, only a Make of the project and a refresh of the Web Script page are necessary.

  8. In the next demo we will add a properties file for the Web Script, create a helloworld.get.properties file next to the other files we have been working with.

    The properties file should have one property as follows:

    hello.word.extras=Extra Stuff From Props 
                            
  9. Add this property to the template, open up helloworld.get.html.ftl.

    The FreeMarker template should now look like this:

    Message: ${fromJS} ${fromJava}  ExtraTemplateText
    ${msg("hello.word.extras")}                      
                            
  10. Now build(Make) the project by clicking Ctrl+S

    The application server log should display messages about the web scripts being refreshed.

  11. Refresh the http://localhost:8080/alfresco/service/sample/helloworld Repository Web Script page from the Browser

    The output of the Web Script should change to "Message: Hello World from JS! UPDATED HelloFromJava ExtraTemplateText Extra Stuff From Props". No restart of application server should be needed, just a Make of the project and a refresh of the Web Script page from the browser.

  12. In the last Web Script demo we will change the Java controller
  13. Open up all-in-one/repo-amp/src/main/java/{your package path}/demoamp/HelloWorldWebScript.java.

    Change the property text as follows:

    public class HelloWorldWebScript extends DeclarativeWebScript {
        protected Map<String, Object> executeImpl(
                WebScriptRequest req, Status status, Cache cache) {
            Map<String, Object> model = new HashMap<String, Object>();
            model.put("fromJava", "HelloFromJavaUPDATED");
            return model;
        }
    }                      
                            
  14. Now build(Make) the project by clicking Ctrl+S

    The application server log should display messages about the web scripts being refreshed.

  15. Refresh the http://localhost:8080/alfresco/service/sample/helloworld Repository Web Script page from the Browser

    The output of the Web Script should change to "Message: Hello World from JS! UPDATED HelloFromJavaUPDATED ExtraTemplateText Extra Stuff From Props". No restart of application server should be needed, just a Make of the project and a refresh of the Web Script page from the browser.

Test Driven Development (TDD) and RAD when doing Repository customizations (alfresco.war).

  1. In the Package Explorer expand all-in-one/repo-amp/src/test/java/{your package path}/demoamp/test and then locate the DemoComponentTest.java source file.
  2. Load it into the editor by double-clicking it.
  3. Now set up a Run Configuration to run repo-amp tests. From the main menu select Run > Run Configurations....
  4. In the Run Configurations dialog, select Maven Build in the left list. Then right click on it and select New.
  5. Set the Name field of the configuration to "Test Repo AMP".
  6. Set the Base Directory field of the configuration to "${workspace_loc:/repo-amp}".
  7. Set the Goals field "test".
  8. In the JRE tab set JDK 8.
  9. Click Apply.
  10. Now run the test by selecting Run.

    The test will run, and three tests will pass, the Console will have logs as follows:

                            
    [INFO] Scanning for projects...
    [INFO]                                                                         
    [INFO] ------------------------------------------------------------------------
    [INFO] Building Alfresco Repository AMP Module 1.0-SNAPSHOT
    [INFO] ------------------------------------------------------------------------
    [INFO] 
    [INFO] --- alfresco-maven-plugin:2.1.0-SNAPSHOT:set-version (default-set-version) @ repo-amp ---
    [INFO] Removed -SNAPSHOT suffix from version - 1.0
    [INFO] Added timestamp to version - 1.0.1505121136
    [INFO] 
    [INFO] --- build-helper-maven-plugin:1.9.1:add-test-resource (add-env-test-properties) @ repo-amp ---
    [INFO] 
    [INFO] --- maven-resources-plugin:2.7:resources (default-resources) @ repo-amp ---
    [INFO] Using 'UTF-8' encoding to copy filtered resources.
    [INFO] skip non existing resourceDirectory /home/martin/src/alfresco-extensions/all-in-one/repo-amp/src/main/resources
    [INFO] Copying 16 resources to ../repo-amp
    [INFO] 
    [INFO] --- yuicompressor-maven-plugin:1.5.1:compress (compress-js) @ repo-amp ---
    [INFO] nothing to do, /home/martin/src/alfresco-extensions/all-in-one/repo-amp/target/classes/../repo-amp/web/scripts/demoamp-min.js is younger than original, use 'force' option or clean your target
    [INFO] nb warnings: 0, nb errors: 0
    [INFO] 
    [INFO] --- alfresco-maven-plugin:2.1.0-SNAPSHOT:refresh (refresh-webscripts-repo-and-share) @ repo-amp ---
    [INFO] Successfull Refresh Web Scripts for Alfresco Repository
    [INFO] 
    [INFO] --- maven-compiler-plugin:3.2:compile (default-compile) @ repo-amp ---
    [INFO] Nothing to compile - all classes are up to date
    [INFO] 
    [INFO] --- maven-resources-plugin:2.7:testResources (default-testResources) @ repo-amp ---
    [INFO] Using 'UTF-8' encoding to copy filtered resources.
    [INFO] Copying 2 resources
    [INFO] Copying 1 resource
    [INFO] 
    [INFO] --- maven-resources-plugin:2.7:copy-resources (add-module-properties-to-test-classpath) @ repo-amp ---
    [INFO] Using 'UTF-8' encoding to copy filtered resources.
    [INFO] Copying 1 resource to alfresco/module/repo-amp
    [INFO] 
    [INFO] --- maven-resources-plugin:2.7:copy-resources (add-module-config-to-test-classpath) @ repo-amp ---
    [INFO] Using 'UTF-8' encoding to copy filtered resources.
    [INFO] Copying 11 resources
    [INFO] 
    [INFO] --- maven-compiler-plugin:3.2:testCompile (default-testCompile) @ repo-amp ---
    [INFO] Nothing to compile - all classes are up to date
    [INFO] 
    [INFO] --- maven-surefire-plugin:2.18:test (default-test) @ repo-amp ---
    [INFO] Surefire report directory: /home/martin/src/alfresco-extensions/all-in-one/repo-amp/target/surefire-reports
    
    -------------------------------------------------------
     T E S T S
    -------------------------------------------------------
    Running org.alfresco.allinone.demoamp.test.DemoComponentTest
    Tests run: 3, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.088 sec - in org.alfresco.allinone.demoamp.test.DemoComponentTest
    
    Results :
    
    Tests run: 3, Failures: 0, Errors: 0, Skipped: 0
    
    [INFO] ------------------------------------------------------------------------
    [INFO] BUILD SUCCESS
    [INFO] ------------------------------------------------------------------------
    [INFO] Total time: 7.232 s
    [INFO] Finished at: 2015-05-12T11:36:13+01:00
    [INFO] Final Memory: 27M/338M
    [INFO] ------------------------------------------------------------------------
    
                        
  11. Now, in DemoComponentTest.java, modify one of the tests so that it will fail. For example, you could change the line assertEquals(7, childNodeCount); to assertEquals(8, childNodeCount);
  12. Now run the test again by selecting Run from main menu and then from Run History select Run 'Test Repo AMP'.

    Note the test will run again and this time fail. But you did not need to restart Alfresco. This demonstrates hot reloading of Java code.

  13. Change the code back and re-run the test.

    Now you will see that all tests pass. The code has re-run without any reloading of Alfresco! This allows for Test Driven Development with very low overhead.

Testing RAD when doing Share customizations (share.war).

  1. In the Package Explorer, navigate to and expand the all-in-one/share-amp/src/main/amp/config/alfresco/web-extension/site-webscripts/com/example/pages folder
  2. Locate the simple-page.get.js file and load it into the editor by double-clicking it.

    This is the controller for the Aikau Page Web Script that we tried after starting the server. Update the controller code by adding an 'UPDATED' string as follows to the page title, also change the layout from HorizontalWidgets to VerticalWidgets:

    model.jsonModel = {
        widgets: [{
            id: "SET_PAGE_TITLE",
            name: "alfresco/header/SetTitle",
            config: {
                title: "This is a simple page UPDATED"
            }
        },
            {
                id: "MY_HORIZONTAL_WIDGET_LAYOUT",
                name: "alfresco/layout/VerticalWidgets",
                config: {
                    widgetWidth: 50,
                    widgets: [
                        {
                            id: "DEMO_SIMPLE_LOGO",
                            name: "alfresco/logo/Logo",
                            config: {
                                logoClasses: "alfresco-logo-only"
                            }
                        },
                        {
                            id: "DEMO_SIMPLE_MSG",
                            name: "example/widgets/TemplateWidget"
                        }
                    ]
                }
            }]
    };                        
  3. Now build(Make) the project by clicking Ctrl+S

    The Share web application will now have the web script container refreshed and the resouce cache cleared.

  4. Refresh the http://localhost:8080/share/page/hdp/ws/simple-page Aikau Page from the Browser

    The page should now display as follows:

  5. Now, let's update some HTML, CSS, and Properties for the sample widget that is used by the Aikau page, navigate to and expand the all-in-one/share-amp/src/main/amp/web/js/example/widgets folder
  6. Locate the css/TemplateWidget.css file and load it into the editor by double-clicking it.

    This is the Stylesheet for the Aikau Widget. Update the widget style as follows:

    .my-template-widget {
        border: 2px #000000 solid;
        padding: 1em;
        width: 100px;
        color: white;
        background-color: blue;
    }                     
  7. Then locate the i18n/TemplateWidget.properties file and load it into the editor by double-clicking it.

    This is the resource file for the the Aikau Widget. Update the properties as follows:

    hello-label=Hello from i18n UPDATED!
    hello-test=Going to use this label too now!
    
  8. Then locate the templates/TemplateWidget.html file and load it into the editor by double-clicking it.

    This is the HTML template file for the the Aikau Widget. Update so it looks as follows:

    <div class="my-template-widget">${greeting} and ${greeting2}</div>
    
  9. And finally, locate the TemplateWidget.js file and load it into the editor by double-clicking it.

    This is the main JavaScript implementation for the Aikau Widget. Update so it also sets the new property used in template:

    define(["dojo/_base/declare",
            "dijit/_WidgetBase",
            "alfresco/core/Core",
            "dijit/_TemplatedMixin",
            "dojo/text!./templates/TemplateWidget.html"
        ],
        function(declare, _Widget, Core, _Templated, template) {
            return declare([_Widget, Core, _Templated], {
                templateString: template,
                i18nRequirements: [ {i18nFile: "./i18n/TemplateWidget.properties"} ],
                cssRequirements: [{cssFile:"./css/TemplateWidget.css"}],
                
                buildRendering: function example_widgets_TemplateWidget__buildRendering() {
                    this.greeting = this.message('hello-label');
                    this.greeting2 = this.message('hello-test');
    
                    this.inherited(arguments);
    
                }
            });
    });
    
  10. Now build(Make) the project by clicking Ctrl+S.
  11. Refresh the http://localhost:8080/share/page/hdp/ws/simple-page Aikau Page from the Browser.

    The page should now display as follows:

Enabling RAD in Eclipse with Run Configurations.

  1. Introduction

    In this article we have seen how we can achieve Rapid Application Development within Eclipse by having the alfresco maven plugin refresh goals executed automatically (magically) after a Make, which is triggered by saving the file. This auto-refresh feature is enabled by default when you use Eclipse. If you don't want that, and instead want to have more control over when web application refreshs happens etc, then you can use a Run Configuration instead and disable auto-refresh. In the following tutorial you will see how run configurations can be used for better control of when the refresh call is being made.

  2. Start by disabling auto-refresh, set the following property in the top project POM (i.e. in alfresco-extensions/all-in-one/pom.xml):

                        
            ...
            <share.client.url>http://localhost:8080/share</share.client.url>
            
            <!--  Turn off auto-refresh of web applications -->
            <maven.alfresco.refresh.mode>none</maven.alfresco.refresh.mode>
        </properties>
     
                    
    Besides none, the other values for this property are:
    • auto - (default) Checks packaging and app.amp.client.war.artifactId to determine if it should refresh Respository (alfresco.war) or Share (share.war)
    • both - Will refresh both Respository and Share
    • share - Refresh only Share
    • repo - Refresh only Respository
    • none - Disables refreshing all together
  3. Then set up a Run Configuration to run repo-amp builds and Repository webapp refresh (alfresco.war). From the main menu select Run > Run Configurations....
  4. In the Run Configurations dialog, select Maven Build in the left list. Then right click on it and select New.
  5. Set the Name field of the configuration to "Make Repo AMP".
  6. Set the Base Directory field of the configuration to "${workspace_loc:/repo-amp}".
  7. Set the Goals field "compile alfresco:refresh-repo".
  8. In the JRE tab set JDK 8.
  9. Click Apply.
  10. Now run the repo-amp build by selecting Run.

    The build will run with the following result, the Eclipse Console will output:

                            
    [INFO] Scanning for projects...
    [INFO]                                                                         
    [INFO] ------------------------------------------------------------------------
    [INFO] Building Alfresco Repository AMP Module 1.0-SNAPSHOT
    [INFO] ------------------------------------------------------------------------
    [INFO] 
    [INFO] --- alfresco-maven-plugin:2.1.0-SNAPSHOT:set-version (default-set-version) @ repo-amp ---
    [INFO] Removed -SNAPSHOT suffix from version - 1.0
    [INFO] Added timestamp to version - 1.0.1505121201
    [INFO] 
    [INFO] --- build-helper-maven-plugin:1.9.1:add-test-resource (add-env-test-properties) @ repo-amp ---
    [INFO] 
    [INFO] --- maven-resources-plugin:2.7:resources (default-resources) @ repo-amp ---
    [INFO] Using 'UTF-8' encoding to copy filtered resources.
    [INFO] skip non existing resourceDirectory /home/martin/src/alfresco-extensions/all-in-one/repo-amp/src/main/resources
    [INFO] Copying 16 resources to ../repo-amp
    [INFO] 
    [INFO] --- yuicompressor-maven-plugin:1.5.1:compress (compress-js) @ repo-amp ---
    [INFO] nothing to do, /home/martin/src/alfresco-extensions/all-in-one/repo-amp/target/classes/../repo-amp/web/scripts/demoamp-min.js is younger than original, use 'force' option or clean your target
    [INFO] nb warnings: 0, nb errors: 0
    [INFO] 
    [INFO] --- alfresco-maven-plugin:2.1.0-SNAPSHOT:refresh (refresh-webscripts-repo-and-share) @ repo-amp ---
    [INFO] Successfull Refresh Web Scripts for Alfresco Repository
    [INFO] 
    [INFO] --- maven-compiler-plugin:3.2:compile (default-compile) @ repo-amp ---
    [INFO] Nothing to compile - all classes are up to date
    [INFO] 
    [INFO] --- alfresco-maven-plugin:2.1.0-SNAPSHOT:refresh-repo (default-cli) @ repo-amp ---
    [INFO] Successfull Refresh Web Scripts for Alfresco Repository
    [INFO] ------------------------------------------------------------------------
    [INFO] BUILD SUCCESS
    [INFO] ------------------------------------------------------------------------
    [INFO] Total time: 8.440 s
    [INFO] Finished at: 2015-05-12T12:01:13+01:00
    [INFO] Final Memory: 29M/342M
    [INFO] ------------------------------------------------------------------------
    
                        
    Note: Note that only the repo-amp is built and only the Repository webapp is refreshed (alfresco.war), the Share application is not touched. This demonstrates how you can have better control of the build and refresh when you have a many different AMPs. You can create a similar run configuration for the share-amp project, and for any other AMP project.
In this tutorial you have seen how to add and modify code within Eclipse and and then see how these changes take effect immediately, without the need to manually restart or refresh any Alfresco Web Applications.
Parent topic: Rapid Application Development (RAD) [9]

Importing SDK projects into IntelliJ IDEA

The Alfresco SDK is designed to work well with IntelliJ IDEA. This support includes the ability to import existing SDK projects (created via the command line) into IDEA.
This task assumes you completed the Installing and configuring software [29] section and generated a project as described in this section [30].
You will learn how to import an existing Maven project into IDEA.
  1. First, make sure IDEA is using the correct Maven installation (3.2.5 or newer). In the main menu, select File > Settings....

    In the IDEA Settings dialog you should see something like this:

  2. Then check that you are using JDK 8, In the main menu, select File > Project Structure....

    In the IDEA Project Structure dialog you should see something like this:

  3. Now, in the main menu, select File > Open...
  4. Navigate to where the project's parent pom is located, in this case the AIO parent pom.

    You should see a dialog looking something like this when you have located an All-in-One (AIO) project:

  5. Select the pom.xml file for the All-in-One parent project.
  6. Click OK. The project is now imported and should appear in the Project tool view to the left.
  7. Enable Alfresco Enterprise edition (Optional)

    If your project is using the Enterprise edition of Alfresco you also want IDEA to load the enterprise versions of the Alfresco WARs and related libraries. You can do this by enable the enterprise profile. In the Maven Projects tool view to the right expand the Profiles folder, then check the enterprise profile. You should see a dialog looking something like this:

  8. Now use Maven to build the All-in-One (AIO) project. Do this by executing the install command on the parent AIO project. In the Maven Projects tool view to the right expand the parent pom, then expand the Lifecycle folder.

    You should see a dialog looking something like this:

  9. Double-click the install plugin goal.

    The project will build, and information will be displayed in the Console. You will see a message similar to the following, indicating that the project was successfully built.

                            
    /usr/lib/jvm/java-8-oracle/bin/java -Xms256m -Xmx1G -XX:PermSize=500m -javaagent:/home/martin/libs/springloaded-1.2.3.RELEASE.jar -noverify -Dmaven.home=/usr/local/apache-maven-3.2.5 ......  install
                            
    [INFO] Reactor Summary:
    [INFO] 
    [INFO] Alfresco Repository and Share Quickstart with database and an embedded Tomcat runner. SUCCESS [  0.387 s]
    [INFO] Alfresco Repository AMP Module ..................... SUCCESS [ 38.368 s]
    [INFO] Alfresco Share AMP Module .......................... SUCCESS [  0.734 s]
    [INFO] Alfresco Repository WAR Aggregator ................. SUCCESS [ 11.000 s]
    [INFO] Alfresco Solr 4 Configuration ...................... SUCCESS [  0.028 s]
    [INFO] Alfresco Share WAR Aggregator ...................... SUCCESS [  9.903 s]
    [INFO] Alfresco, Share and Solr4 Tomcat Runner ............ SUCCESS [  0.007 s]
    [INFO] ------------------------------------------------------------------------
    [INFO] BUILD SUCCESS
    [INFO] ------------------------------------------------------------------------
    [INFO] Total time: 01:01 min
    [INFO] Finished at: 2015-05-06T11:28:02+01:00
    [INFO] Final Memory: 61M/503M
    [INFO] ------------------------------------------------------------------------
    
    Process finished with exit code 0
    
                        
    Attention: You should see that the MAVEN_OPTS setting has been picked up by IDEA, look at the first line of the log.
You have seen how to import your SDK project into IntelliJ and how to build it.
Parent topic: Rapid Application Development (RAD) [9]

Rapid Application Development in IntelliJ IDEA (Hot reloading)

Hot reloading is the ability to modify your application's code, and view the changes without having to restart Alfresco Tomcat. This allows for significant savings in development time that would otherwise be wasted restarting Tomcat. Hot reloading is the key to enabling Rapid Application Development (RAD) and Test Driven Development (TDD).
You should have an extension project imported, see importing a project into IDEA [68].
In this tutorial you will see how changes to your code can be carried out without having to restart Alfresco Tomcat. This tutorial demonstrates hot reloading of JavaScript, FreeMarker template, and Java code. There are three components that work together to enable the best RAD experience:
  1. Spring Loaded: takes care of hot-reloading any Java class files that we have changed.
  2. Refresh Repository Script: This is a script that will POST a request to the Alfresco repository web application (that is, alfresco.war) telling it to refresh the Repo web script container, so any changes to files related to web scripts will be picked up.
  3. Refresh Share Script: This is a script that will POST a request to the Alfresco Share web application (that is, share.war) telling it to refresh the Surf web script container, so any changes to files related to Surf web scripts will be picked up. This script will also clear the resource dependency caches, so JS changes etc are picked up.

Start an instance of Alfresco Tomcat that will be used for hot-reloading.

  1. Use the run script to start the Application server with the Alfresco extension project deployed, for example:

    alfresco-extensions/all-in-one$ ./run.sh                        
                                               
    Important: This is usually done outside the IDE.
  2. Test the custom repository web script

    The All-in-One project (and the repository AMP project) have a sample web script included. You can invoke it by pointing your web browser at http://localhost:8080/alfresco/service/sample/helloworld. If you need to login then use admin with password admin. Running this web script produces the output "Message: Hello World from JS! HelloFromJava".

  3. Test the custom Share Aikau Page

    The All-in-One project (and the Share AMP project) have a sample Aikau page included. You can display it by pointing your web browser at http://localhost:8080/share/page/hdp/ws/simple-page. If you need to login then use admin with password admin. The page should display as follows:

Enabling Rapid Application Development (RAD) in IDEA.

  1. Configure repository AMP projects to Refresh Webapp (alfresco.war)

    The All-in-One project has one Repository AMP project by default (all-in-one/repo-amp), we need to set up IDEA so that when we build via IDEA (that is, not via Maven) a script runs that will refresh the Repo Web Script container. In the Maven Projects tool view to the right expand the Alfresco Repository AMP Module folder, then expand the Plugins folder. Now expand the alfresco plugin folder. Right click on the alfresco:refresh-repo goal of the plugin. In the drop down menu select Execute After Make. You should now see a dialog looking something like this:

    If you are working with multiple Repo AMPs [69], then you need to do this configuration for each one of them.
    Important: You only need to do this if you are doing customizations for the Alfresco repository webapp (that is, customizing alfresco.war). If you are just customizing the Share UI, see the next configuration.
  2. Configure Share AMP projects to Refresh Webapp (share.war)

    The All-in-One project has one Share AMP project by default (all-in-one/share-amp), we need to set up IDEA so that when we build via IDEA (that is, not via Maven) a script runs that will refresh the Surf Web Script container and clear dependency caches. In the Maven Projects tool view to the right expand the Alfresco Share AMP Module folder, then expand the Plugins folder. Now expand the alfresco plugin folder. Right click on the alfresco:refresh-share goal of the plugin. In the drop down menu select Execute After Make. You should now see a dialog looking something like this:

    If you are working with multiple Share AMPs [69], then you need to do this configuration for each one of them.
    Important: You only need to do this if you are doing customizations for the Alfresco Share webapp (that is, customizing share.war). If you are just customizing the repository, see the previous configuration.

Testing RAD when doing repository customizations (alfresco.war).

  1. In the Project Explorer, navigate to and expand the all-in-one/repo-amp/src/main/amp/config/alfresco/extension/templates/webscripts folder
  2. Locate the helloworld.get.js file and load it into the editor by double-clicking it.

    This is the controller for the web script that we tried after starting the server. Update the controller code by adding an 'UPDATED' string as follows:

    model["fromJS"] = "Hello World from JS! UPDATED";
                            
  3. Now build(Make) the project by clicking Ctrl+F9

    The message console in IDEA should display BUILD SUCCESS for both the repo-amp and share-amp modules as follows:

    [INFO] Scanning for projects...
    [INFO]                                                                         
    [INFO] ------------------------------------------------------------------------
    [INFO] Building Alfresco Repository AMP Module 1.0-SNAPSHOT
    [INFO] ------------------------------------------------------------------------
    [INFO] 
    [INFO] --- alfresco-maven-plugin:2.1.0-SNAPSHOT:refresh-repo (default-cli) @ repo-amp ---
    [INFO] Successfull Refresh Web Scripts for Alfresco Repository
    [INFO] ------------------------------------------------------------------------
    [INFO] BUILD SUCCESS
    [INFO] ------------------------------------------------------------------------
    [INFO] Total time: 3.854 s
    [INFO] Finished at: 2015-05-11T10:20:17+01:00
    [INFO] Final Memory: 15M/315M
    [INFO] ------------------------------------------------------------------------
    [INFO] Scanning for projects...
    [INFO]                                                                         
    [INFO] ------------------------------------------------------------------------
    [INFO] Building Alfresco Share AMP Module 1.0-SNAPSHOT
    [INFO] ------------------------------------------------------------------------
    [INFO] 
    [INFO] --- alfresco-maven-plugin:2.1.0-SNAPSHOT:refresh-share (default-cli) @ share-amp ---
    [INFO] Successfull Refresh Web Scripts for Alfresco Share
    [INFO] Successfull Clear Dependency Caches for Alfresco Share
    [INFO] ------------------------------------------------------------------------
    [INFO] BUILD SUCCESS
    [INFO] ------------------------------------------------------------------------
    [INFO] Total time: 4.173 s
    [INFO] Finished at: 2015-05-11T10:20:24+01:00
    [INFO] Final Memory: 18M/309M
    [INFO] ------------------------------------------------------------------------
    [INFO] Maven execution finished                       
                            
    Note the refresh calls to the web applications. If you would prefer to only refresh the repository webapp (that is, alfresco.war) have a look later on in this article for a different approach to refreshing the webapp via run configurations.
  4. Refresh the http://localhost:8080/alfresco/service/sample/helloworld Repository Web Script page from the Browser

    The output from the web script should change to "Message: Hello World from JS! UPDATED HelloFromJava". Note that there is no need to restart the application server, just a Make of the project, and a refresh of the web script page from the browser (you are basically invoking the web script again and the update should be immediately visible).

  5. Now locate the helloworld.get.html.ftl file and double-click it to load it into the editor.

    This is the FreeMarker template for the web script. Update the template by adding an 'ExtraTemplateText' string as follows:

    Message: ${fromJS} ${fromJava} ExtraTemplateText                       
                            
  6. Now build(Make) the project by clicking Ctrl+F9

    The message console in IDEA should display BUILD SUCCESS

  7. Refresh the http://localhost:8080/alfresco/service/sample/helloworld Repository Web Script page from the Browser

    The output from the web script should change to "Message: Hello World from JS! UPDATED HelloFromJava ExtraTemplateText ". Again, note that there is no need to restart the application server, only a Make of the project and a refresh of the web script page are necessary.

  8. In the next demo we will add a properties file for the web script, create a helloworld.get.properties file next to the other files we have been working with.

    The properties file should have one property as follows:

    hello.word.extras=Extra Stuff From Props 
                            
  9. Add this property to the template, open up helloworld.get.html.ftl.

    The FreeMarker template should now look like this:

    Message: ${fromJS} ${fromJava}  ExtraTemplateText
    ${msg("hello.word.extras")}                      
                            
  10. Now build(Make) the project by clicking Ctrl+F9

    The message console in IDEA should display BUILD SUCCESS.

  11. Refresh the http://localhost:8080/alfresco/service/sample/helloworld Repository Web Script page from the Browser

    The output of the web script should change to "Message: Hello World from JS! UPDATED HelloFromJava ExtraTemplateText Extra Stuff From Props". No restart of application server should be needed, just a Make of the project and a refresh of the web script page from the browser.

  12. In the last web script demo we will change the Java controller
  13. Open up all-in-one/repo-amp/src/main/java/{your package path}/demoamp/HelloWorldWebScript.java.

    Change the property text as follows:

    public class HelloWorldWebScript extends DeclarativeWebScript {
        protected Map<String, Object> executeImpl(
                WebScriptRequest req, Status status, Cache cache) {
            Map<String, Object> model = new HashMap<String, Object>();
            model.put("fromJava", "HelloFromJavaUPDATED");
            return model;
        }
    }                      
                            
  14. Now build(Make) the project by clicking Ctrl+F9

    The message console in IDEA should display BUILD SUCCESS.

  15. Refresh the http://localhost:8080/alfresco/service/sample/helloworld Repository Web Script page from the Browser

    The output of the web script should change to "Message: Hello World from JS! UPDATED HelloFromJavaUPDATED ExtraTemplateText Extra Stuff From Props". No restart of application server should be needed, just a Make of the project and a refresh of the web script page from the browser.

Test Driven Development (TDD) and RAD when doing Repository customizations (alfresco.war).

  1. In the IntelliJ Project Explorer expand all-in-one/repo-amp/src/test/java/{your package path}/demoamp/test and then locate the DemoComponentTest.java source file.
  2. Load it into the editor by double-clicking it.
  3. Now set up a Run Configuration to run repo-amp tests. From the main menu select Run > Edit Configurations.
  4. In the Run/Debug Configurations dialog, click '+' to create a new configuration. Select Maven from the list of available configuration types.
  5. Set the Name field of the configuration to "Test Repo AMP".
  6. Set the Working Directory field of the configuration to "alfresco-extensions/all-in-one/repo-amp".
  7. Set the Command line field "test".
  8. Click OK.
  9. Now run the test by selecting Run > Run 'Test Repo AMP' from the main menu.

    The test will run, and three tests will pass:

                            
    /usr/lib/jvm/java-8-oracle/bin/java -Xms256m -Xmx1G -javaagent:/home/martin/libs/springloaded-1.2.3.RELEASE.jar -noverify -Dmaven.home=/usr/local/apache-maven-3.2.5 ....
    [INFO] Scanning for projects...
    [INFO]                                                                         
    [INFO] ------------------------------------------------------------------------
    [INFO] Building Alfresco Repository AMP Module 1.0-SNAPSHOT
    [INFO] ------------------------------------------------------------------------
    [INFO] 
    [INFO] --- alfresco-maven-plugin:2.1.0-SNAPSHOT:set-version (default-set-version) @ repo-amp ---
    [INFO] Removed -SNAPSHOT suffix from version - 1.0
    [INFO] Added timestamp to version - 1.0.1505120757
    [INFO] 
    [INFO] --- build-helper-maven-plugin:1.9.1:add-test-resource (add-env-test-properties) @ repo-amp ---
    [INFO] 
    [INFO] --- maven-resources-plugin:2.7:resources (default-resources) @ repo-amp ---
    [INFO] Using 'UTF-8' encoding to copy filtered resources.
    [INFO] skip non existing resourceDirectory /home/martin/src/alfresco-extensions/all-in-one/repo-amp/src/main/resources
    [INFO] Copying 14 resources to ../repo-amp
    [INFO] 
    [INFO] --- yuicompressor-maven-plugin:1.5.1:compress (compress-js) @ repo-amp ---
    [INFO] nothing to do, /home/martin/src/alfresco-extensions/all-in-one/repo-amp/target/classes/../repo-amp/web/scripts/demoamp-min.js is younger than original, use 'force' option or clean your target
    [INFO] nb warnings: 0, nb errors: 0
    [INFO] 
    [INFO] --- alfresco-maven-plugin:2.1.0-SNAPSHOT:refresh (refresh-webscripts-repo-and-share) @ repo-amp ---
    [INFO] Successfull Refresh Web Scripts for Alfresco Repository
    [INFO] 
    [INFO] --- maven-compiler-plugin:3.2:compile (default-compile) @ repo-amp ---
    [INFO] Nothing to compile - all classes are up to date
    [INFO] 
    [INFO] --- maven-resources-plugin:2.7:testResources (default-testResources) @ repo-amp ---
    [INFO] Using 'UTF-8' encoding to copy filtered resources.
    [INFO] Copying 2 resources
    [INFO] Copying 1 resource
    [INFO] 
    [INFO] --- maven-resources-plugin:2.7:copy-resources (add-module-properties-to-test-classpath) @ repo-amp ---
    [INFO] Using 'UTF-8' encoding to copy filtered resources.
    [INFO] Copying 1 resource to alfresco/module/repo-amp
    [INFO] 
    [INFO] --- maven-resources-plugin:2.7:copy-resources (add-module-config-to-test-classpath) @ repo-amp ---
    [INFO] Using 'UTF-8' encoding to copy filtered resources.
    [INFO] Copying 9 resources
    [INFO] 
    [INFO] --- maven-compiler-plugin:3.2:testCompile (default-testCompile) @ repo-amp ---
    [INFO] Nothing to compile - all classes are up to date
    [INFO] 
    [INFO] --- maven-surefire-plugin:2.18:test (default-test) @ repo-amp ---
    [INFO] Surefire report directory: /home/martin/src/alfresco-extensions/all-in-one/repo-amp/target/surefire-reports
    
    -------------------------------------------------------
     T E S T S
    -------------------------------------------------------
    Running org.alfresco.allinone.demoamp.test.DemoComponentTest
    Tests run: 3, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.085 sec - in org.alfresco.allinone.demoamp.test.DemoComponentTest
    
    Results :
    
    Tests run: 3, Failures: 0, Errors: 0, Skipped: 0
    
    [INFO] ------------------------------------------------------------------------
    [INFO] BUILD SUCCESS
    [INFO] ------------------------------------------------------------------------
    [INFO] Total time: 6.946 s
    [INFO] Finished at: 2015-05-12T07:57:24+01:00
    [INFO] Final Memory: 25M/443M
    [INFO] ------------------------------------------------------------------------                   
                            
                        
  10. Now, in DemoComponentTest.java, modify one of the tests so that it will fail. For example, you could change the line assertEquals(7, childNodeCount); to assertEquals(8, childNodeCount);
  11. Now run the test again by right-clicking the file in Project Explorer and selecting Run 'Test Repo AMP'.

    Note the test will run again and this time fail. But you did not need to restart Alfresco. This demonstrates hot reloading of Java code.

  12. Change the code back and re-run the test.

    Now you will see that all tests pass. The code has re-run without any reloading of Alfresco! This allows for Test Driven Development with very low overhead.

Testing RAD when doing Share customizations (share.war).

  1. In the Project Explorer, navigate to and expand the all-in-one/share-amp/src/main/amp/config/alfresco/web-extension/site-webscripts/com/example/pages folder
  2. Locate the simple-page.get.js file and load it into the editor by double-clicking it.

    This is the controller for the Aikau Page web script that we tried after starting the server. Update the controller code by adding an 'UPDATED' string as follows to the page title, also change the layout from HorizontalWidgets to VerticalWidgets:

    model.jsonModel = {
        widgets: [{
            id: "SET_PAGE_TITLE",
            name: "alfresco/header/SetTitle",
            config: {
                title: "This is a simple page UPDATED"
            }
        },
            {
                id: "MY_HORIZONTAL_WIDGET_LAYOUT",
                name: "alfresco/layout/VerticalWidgets",
                config: {
                    widgetWidth: 50,
                    widgets: [
                        {
                            id: "DEMO_SIMPLE_LOGO",
                            name: "alfresco/logo/Logo",
                            config: {
                                logoClasses: "alfresco-logo-only"
                            }
                        },
                        {
                            id: "DEMO_SIMPLE_MSG",
                            name: "example/widgets/TemplateWidget"
                        }
                    ]
                }
            }]
    };                        
  3. Now build(Make) the project by clicking Ctrl+F9

    The message console in IDEA should display BUILD SUCCESS for both the repo-amp and share-amp modules as follows:

    [INFO] Scanning for projects...
    [INFO]                                                                         
    [INFO] ------------------------------------------------------------------------
    [INFO] Building Alfresco Repository AMP Module 1.0-SNAPSHOT
    [INFO] ------------------------------------------------------------------------
    [INFO] 
    [INFO] --- alfresco-maven-plugin:2.1.0-SNAPSHOT:refresh-repo (default-cli) @ repo-amp ---
    [INFO] Successfull Refresh Web Scripts for Alfresco Repository
    [INFO] ------------------------------------------------------------------------
    [INFO] BUILD SUCCESS
    [INFO] ------------------------------------------------------------------------
    [INFO] Total time: 3.854 s
    [INFO] Finished at: 2015-05-11T10:20:17+01:00
    [INFO] Final Memory: 15M/315M
    [INFO] ------------------------------------------------------------------------
    [INFO] Scanning for projects...
    [INFO]                                                                         
    [INFO] ------------------------------------------------------------------------
    [INFO] Building Alfresco Share AMP Module 1.0-SNAPSHOT
    [INFO] ------------------------------------------------------------------------
    [INFO] 
    [INFO] --- alfresco-maven-plugin:2.1.0-SNAPSHOT:refresh-share (default-cli) @ share-amp ---
    [INFO] Successfull Refresh Web Scripts for Alfresco Share
    [INFO] Successfull Clear Dependency Caches for Alfresco Share
    [INFO] ------------------------------------------------------------------------
    [INFO] BUILD SUCCESS
    [INFO] ------------------------------------------------------------------------
    [INFO] Total time: 4.173 s
    [INFO] Finished at: 2015-05-11T10:20:24+01:00
    [INFO] Final Memory: 18M/309M
    [INFO] ------------------------------------------------------------------------
    [INFO] Maven execution finished                       
                            
    Also, note the refresh calls to the Web Applications to refresh. If you would prefer to only refresh the Share webapp (that is, share.war) have a look later on in this article for a different approach to refreshing the webapp via run configurations.
  4. Refresh the http://localhost:8080/share/page/hdp/ws/simple-page Aikau Page from the Browser

    The page should now display as follows:

  5. Now, let's update some HTML, CSS, and Properties for the sample widget that is used by the Aikau page, navigate to and expand the all-in-one/share-amp/src/main/amp/web/js/example/widgets folder
  6. Locate the css/TemplateWidget.css file and load it into the editor by double-clicking it.

    This is the Stylesheet for the Aikau Widget. Update the widget style as follows:

    .my-template-widget {
        border: 2px #000000 solid;
        padding: 1em;
        width: 100px;
        color: white;
        background-color: blue;
    }                     
  7. Then locate the i18n/TemplateWidget.properties file and load it into the editor by double-clicking it.

    This is the resource file for the the Aikau Widget. Update the properties as follows:

    hello-label=Hello from i18n UPDATED!
    hello-test=Going to use this label too now!
    
  8. Then locate the templates/TemplateWidget.html file and load it into the editor by double-clicking it.

    This is the HTML template file for the the Aikau Widget. Update so it looks as follows:

    <div class="my-template-widget">${greeting} and ${greeting2}</div>
    
  9. And finally, locate the TemplateWidget.js file and load it into the editor by double-clicking it.

    This is the main JavaScript implementation for the Aikau Widget. Update so it also sets the new property used in template:

    define(["dojo/_base/declare",
            "dijit/_WidgetBase",
            "alfresco/core/Core",
            "dijit/_TemplatedMixin",
            "dojo/text!./templates/TemplateWidget.html"
        ],
        function(declare, _Widget, Core, _Templated, template) {
            return declare([_Widget, Core, _Templated], {
                templateString: template,
                i18nRequirements: [ {i18nFile: "./i18n/TemplateWidget.properties"} ],
                cssRequirements: [{cssFile:"./css/TemplateWidget.css"}],
                
                buildRendering: function example_widgets_TemplateWidget__buildRendering() {
                    this.greeting = this.message('hello-label');
                    this.greeting2 = this.message('hello-test');
    
                    this.inherited(arguments);
    
                }
            });
    });
    
  10. Now build(Make) the project by clicking Ctrl+F9.
  11. Refresh the http://localhost:8080/share/page/hdp/ws/simple-page Aikau Page from the Browser.

    The page should now display as follows:

Enabling RAD in IDEA with run configurations.

  1. Introduction

    In this article we have seen how we can achieve Rapid Application Development within IDEA by executing alfresco maven plugin refresh goals after a Make. This is an easy way to configure RAD in IDEA when you are only working with 1 or 2 AMPs. However, when you start to get a number of AMPs that you are working on simultaneously, then there will be a lot of refresh calls going on as every AMP's alfresco plugin goal config will be executed. This could be seen in the tutorials above where the refresh-share and refresh-repo goals were always executed even if we were just working with one of the associated AMPs. In the following tutorial you will see how run configurations can be used for better control of when the refresh call is being made.

  2. Set up a Run Configuration to run repo-amp builds and Repository webapp refresh (alfresco.war). From the main menu select Run > Edit Configurations.
  3. In the Run/Debug Configurations dialog, click '+' to create a new configuration. Select Maven from the list of available configuration types.
  4. Set the Name field of the configuration to "Make Repo AMP".
  5. Set the Working Directory field of the configuration to "alfresco-extensions/all-in-one/repo-amp".
  6. Set the Command line field "compile alfresco:refresh-repo".
  7. Click OK.
  8. Now do a Make(build) by selecting Run > Run 'Make Repo AMP' from the main menu.

    The build will run with the following result:

                            
    /usr/lib/jvm/java-8-oracle/bin/java -Xms256m -Xmx1G -javaagent:/home/martin/libs/springloaded-1.2.3.RELEASE.jar -noverify -Dmaven.home=/usr/local/apache-maven-3.2.5 ....
    [INFO] Scanning for projects...
    [INFO]                                                                         
    [INFO] ------------------------------------------------------------------------
    [INFO] Building Alfresco Repository AMP Module 1.0-SNAPSHOT
    [INFO] ------------------------------------------------------------------------
    [INFO] 
    [INFO] --- alfresco-maven-plugin:2.1.0-SNAPSHOT:set-version (default-set-version) @ repo-amp ---
    [INFO] Removed -SNAPSHOT suffix from version - 1.0
    [INFO] Added timestamp to version - 1.0.1505120823
    [INFO] 
    [INFO] --- build-helper-maven-plugin:1.9.1:add-test-resource (add-env-test-properties) @ repo-amp ---
    [INFO] 
    [INFO] --- maven-resources-plugin:2.7:resources (default-resources) @ repo-amp ---
    [INFO] Using 'UTF-8' encoding to copy filtered resources.
    [INFO] skip non existing resourceDirectory /home/martin/src/alfresco-extensions/all-in-one/repo-amp/src/main/resources
    [INFO] Copying 14 resources to ../repo-amp
    [INFO] 
    [INFO] --- yuicompressor-maven-plugin:1.5.1:compress (compress-js) @ repo-amp ---
    [INFO] nothing to do, /home/martin/src/alfresco-extensions/all-in-one/repo-amp/target/classes/../repo-amp/web/scripts/demoamp-min.js is younger than original, use 'force' option or clean your target
    [INFO] nb warnings: 0, nb errors: 0
    [INFO] 
    [INFO] --- alfresco-maven-plugin:2.1.0-SNAPSHOT:refresh (refresh-webscripts-repo-and-share) @ repo-amp ---
    [INFO] Successfull Refresh Web Scripts for Alfresco Repository
    [INFO] 
    [INFO] --- maven-compiler-plugin:3.2:compile (default-compile) @ repo-amp ---
    [INFO] Nothing to compile - all classes are up to date
    [INFO] 
    [INFO] --- alfresco-maven-plugin:2.1.0-SNAPSHOT:refresh-repo (default-cli) @ repo-amp ---
    [INFO] Successfull Refresh Web Scripts for Alfresco Repository
    [INFO] ------------------------------------------------------------------------
    [INFO] BUILD SUCCESS
    [INFO] ------------------------------------------------------------------------
    [INFO] Total time: 6.389 s
    [INFO] Finished at: 2015-05-12T08:23:57+01:00
    [INFO] Final Memory: 30M/490M
    [INFO] ------------------------------------------------------------------------                        
                        
    Note: Note that only the repo-amp is built and only the repository webapp is refreshed (alfresco.war), the Share application is not touched. This demonstrates how you can have better control of the build and refresh when you have a many different AMPs. You can create a similar run configuration for the share-amp project, and for any other AMP project.
In this tutorial you have seen how to add and modify code within IntelliJ IDEA and then see how these changes take effect immediately, without the need to manually restart or refresh any Alfresco web applications.
Parent topic: Rapid Application Development (RAD) [9]

Remote debugging with an IDE

It is possible to start an application ready for remote debugging by using the Maven mvnDebug command. Eclipse or another development environment such as IDEA can then connect to the running application for remote debugging.
You should have an extension project imported, see importing a project into Eclipse [67].
It is quite common that you would need to debug Java code associated with an Alfresco extension you are developing. For example, if you are developing a Java backed Web Script. The command mvnDebug can be used to start the application in remote debugging mode, where it will listen on port 8000, ready for a remote debugger to attach.
  1. In this tutorial we assume that we are working with an All-in-One (AIO) project, change into the top directory (alfresco-extensions/all-in-one).

Start the AIO project in debug mode.

  1. Run mvnDebug rather than the mvn command:

    $ mvnDebug clean install -Prun
    Preparing to Execute Maven in Debug Mode
    Listening for transport dt_socket at address: 8000
    ...
                            
                        
    The Maven project will start and listen for a remote debugger on port 8000.
    Important: This is usually done outside the IDE.

Connect to the running application process from Eclipse

  1. In Eclipse, select Run > Debug Configurations from the main menu.
  2. Select Remote Java Application and click the New icon on the top left of the dialog.
  3. Give the Debug Configuration a suitable name, such as "Debug Alfresco Extension".
  4. Click Browse and select the repo-amp project, the rest of the fields for host and port have suitable default values.
  5. Click Apply.
  6. Click Debug to run the Debug Configuration and connect to the remote Alfresco server.
  7. In Eclipse, enable the Debug perspective by selecting Window > Open Perspective > Debug from the main menu.
  8. Set a breakpoint in the all-in-one/repo-amp/src/main/java/org/alfresco/allinone/demoamp/HelloWorldWebScript.java) file.
  9. Invoke the http://localhost:8080/alfresco/service/sample/helloworld Repository Web Script from the Browser

    You should now see the process stopping in the debugger as follows:

Parent topic: Rapid Application Development (RAD) [9]

Advanced Topics

This section goes through more advanced topics that you might come in contact with when you have been working with an SDK project for a while. We will have a look at how you can add more custom modules to an All-in-One project, how to bring in standard Alfresco modules such as Records Management (RM) and SharePoint Protocol (SPP) support, configuring SSL, and more.
  • Configure SSL between Repository and Solr in an AIO project [70] The SDK ships with SSL turned off between the Alfresco Repository and the Solr 4 search server. This article explains how to set that up when running an All-in-One (AIO) project.
  • Adding internal and external JARs to a Repository AMP project [71] This article explains how to add an external JAR to a Repository AMP project via a dependency. It also looks at how to extract some AMP code into its own JAR project, what we call an internal JAR, and then have the AMP project include it.
  • Linking Standard Alfresco AMPs to an AIO project [72] Some functionality of the Alfresco content management system is delivered as extra modules, such as for example Records Management (RM), Google Docs Integration, and SharePoint Protocol (SPP) Support. This sections goes through how to link such modules to an All-in-One (AIO) project.
  • Adding more custom AMPs to an AIO project [69] When you generate an All-in-One project you get one Repository extension AMP (repo-amp) and one Share extension AMP (share-amp). These AMPs are just starting point AMPs, showing you how to create extension AMPs for the Alfresco WAR and Share WAR applications. When the project grows you are likely to want to add more extension modules for different types of functionality.
Parent topic: Alfresco SDK 2.1 [14]

Configure SSL between Repository and Solr in an AIO project

The SDK ships with SSL turned off between the Alfresco Repository and the Solr 4 search server. This article explains how to set that up when running an All-in-One (AIO) project.
This task assumes you completed the Installing and Configuring software [29] section and generated an AIO project as described in this section [57]. You will also need access to an Alfresco 5 installation as we need to copy the keystore and Tomcat users file from it.
You will learn how to setup a secure connection (SSL) between the Alfresco Repository web application (alfresco.war) and the Apache Solr 4 web application (alfresco-solr4.war). This is the normal configuration after you have installed Alfresco with a package installer. In the following instructions ALFRESCO_INSTALL_DIR is the directory path to where you installed Alfresco 5 with the package installer (for example /opt/alfresco5). And AIO_PARENT_DIR points to where the parent project directory is for the All-in-One (AIO) project (for example /home/martin/src/all-in-one).
  1. Stop the embedded Tomcat instance, if it is running.
  2. Copy the Repository keystore to the AIO project.

    Execute the following command to copy the keystore into the runner project:

    {ALFRESCO_INSTALL_DIR}/alf_data$ cp -R keystore/ {AIO_PARENT_DIR}/runner/
    We can now configure the embedded Tomcat instace to use this keystore.
  3. Copy Tomcat users definition to the AIO project.

    Execute the following command to copy the tomcat users file into the runner project:

    {AIO_PARENT_DIR}/runner/tomcat$ mkdir conf
    {ALFRESCO_INSTALL_DIR}/tomcat/conf$ cp tomcat-users.xml {AIO_PARENT_DIR}/runner/tomcat/conf/
    What we do here is first create a directory to hold the tomcat users file. And then we copy the tomcat users file from the Alfresco installation to this new directory in the runner project. This file contains identities for the Repository and Solr applications when setting up SSL connections.
  4. Turn on SSL for Repository.

    Open up the alfresco-global.properties file located in the {AIO_PARENT_DIR}/repo/src/main/properties/local directory. Then update the section about Solr configuration:

    index.subsystem.name=solr4
    dir.keystore={AIO_PARENT_DIR}/runner/keystore
    solr.host=localhost
    solr.port=8080
    solr.port.ssl=8443
    #solr.secureComms=none
    Note. You have to change {AIO_PARENT_DIR} to whatever the parent directory is for your AIO project.
  5. Update the tomcat7-maven-plugin with keystore, port, and Tomcat users

    Open up the pom.xml file located in the {AIO_PARENT_DIR}/runner directory. Then update the plugin configuration as follows:

    <plugin>
       <groupId>org.apache.tomcat.maven</groupId>
       <artifactId>tomcat7-maven-plugin</artifactId>
       <executions>
           <execution>
               <id>run-wars</id>
               <goals>
                   <goal>run</goal>
               </goals>
               <phase>pre-integration-test</phase>
           </execution>
       </executions>
       <configuration>
           <httpsPort>8443</httpsPort>
           <keystoreFile>${project.basedir}/keystore/ssl.keystore</keystoreFile>
           <keystorePass>kT9X6oe68t</keystorePass>
           <keystoreType>JCEKS</keystoreType>
           <truststoreFile>${project.basedir}/keystore/ssl.truststore</truststoreFile>
           <truststorePass>kT9X6oe68t</truststorePass>
           <truststoreType>JCEKS</truststoreType>
           <tomcatUsers>${project.basedir}/tomcat/conf/tomcat-users.xml</tomcatUsers>
  6. Change Solr4 configuration package to the one that has SSL enabled.

    Open up the pom.xml file located in the {AIO_PARENT_DIR}/solr-config directory. Then update the dependency and plugin configuration as follows:

    <dependencies>
       <dependency>
           <groupId>org.alfresco</groupId>
           <artifactId>alfresco-solr4</artifactId>
           <version>${alfresco.version}</version>
           <classifier>config-ssl</classifier>
           <type>zip</type>
       </dependency>
    </dependencies>
    
    <build>
       <plugins>
           <plugin>
               <groupId>org.apache.maven.plugins</groupId>
               <artifactId>maven-dependency-plugin</artifactId>
               <executions>
                   <execution>
                       <id>unpack-alfresco-config</id>
                       <goals>
                           <goal>unpack</goal>
                       </goals>
                       <phase>generate-resources</phase>
                       <configuration>
                           <outputDirectory>${alfresco.solr.home.dir}</outputDirectory>
                           <artifactItems>
                               <artifactItem>
                                   <groupId>org.alfresco</groupId>
                                   <artifactId>alfresco-solr4</artifactId>
                                   <version>${alfresco.version}</version>
                                   <classifier>config-ssl</classifier>
                                   <type>zip</type>
                               </artifactItem>
                           </artifactItems>
    This Solr4 configuration comes preconfigured with SSL enabled, keystore and truststore, including the keystores themselves.
  7. Delete previous "no-ssl" configuration directory.

    {AIO_PARENT_DIR}/alf_data_dev/solr4$ rm -rf config/
    This is so the new SSL enabled configuration is downloaded and installed correctly under alf_data_dev.
  8. Make sure that the Alfresco Repository (alfresco.war) web application is using SSL.

    Open up the pom.xml file located in the {AIO_PARENT_DIR}/repo directory. Then update the maven-war-plugin configuration as follows:

    <plugin>
       <artifactId>maven-war-plugin</artifactId>
       <executions>
           <execution>
               <id>prepare-exploded-war</id>
               <goals>
                   <goal>exploded</goal>
               </goals>
               <phase>prepare-package</phase>
           </execution>
           <execution>
               <id>default-war</id>
              <!-- <configuration>
                    <webXml>${project.build.directory}/${project.build.finalName}-nossl/WEB-INF/web.xml</webXml>
               </configuration>-->
           </execution>
       </executions>
    What we do here is just commenting out the web.xml file that we normally use when we don't want to use SSL.
  9. Start it up and make sure it works.

    You should see something like this in the logs:

    {AIO_PARENT_DIR}$ mvn clean install -Prun
    ...
    Jun 05, 2015 10:56:33 AM org.apache.coyote.AbstractProtocol start
    INFO: Starting ProtocolHandler ["http-bio-8080"]
    Jun 05, 2015 10:56:33 AM org.apache.coyote.AbstractProtocol start
    INFO: Starting ProtocolHandler ["http-bio-8443"]
    Try accessing Share securely: https://localhost:8443/share. Make sure search works by adding a text file with a unique word, then search for it. Then access Solr4 securely: https://localhost:8443/solr4.
You have now setup SSL between the Alfresco Repository and the Solr4 server.
Parent topic: Advanced Topics [10]

Adding internal and external JARs to a Repository AMP project

This article explains how to add an external JAR to a Repository AMP project via a dependency. It also looks at how to extract some AMP code into its own JAR project, what we call an internal JAR, and then have the AMP project include it.
This task assumes you completed the Installing and Configuring software [29] section and generated an Repo AMP project as described in this section [58].To try out the examples in this article you will need to install a local SMTP server such as Fake SMTP [73].

Sometimes when you are developing a Repository AMP you need to include external libraries (JARs) that are not part/are not available in the tomcat/webapps/alfresco/WEB­INF/lib​directory. Being able to do this is one of the benefits of AMPs compared to other extension models. The Repository AMP might also start to grow to a size where it would make sense to move some of the functionality over to separate JAR projects, and have the AMP depend on them. This article goes through how to do these things.

Adding an external JAR to a Repository AMP project.

Note: An external JAR is needed when you want to use some library that is not part of the Alfresco Repository (alfresco.war) web application. Meaning it is not present in the tomcat/webapps/alfresco/WEB-INF/lib directory. So you should always first scan this directory in an Alfresco Community or Enterprise installation to see if the library is available. If it is available, then you can include it in the componentX-repo/pom.xml as a provided dependency.

In the following example we will update the Hello World Web Script code (it is part of the Repository AMP source code) so that it can send emails. However, when we select a Mail library to use for this, we forget to check if the library is already available as part of the Alfresco Repository WAR. We will see what happens then and how to fix it:

  1. Stop the embedded Tomcat instance, if it is running (i.e. via -Pamp-to-war).
  2. Find a library that can be used to send emails from Java and add a dependency for it to the Repo AMP project.

    We know that the Java Mail library can be used for this, so we look up the maven dependency for it and add it to the componentX-repo/pom.xml:

    ...                            
    <dependencies>
        <dependency>
           <groupId>${alfresco.groupId}</groupId>
           <artifactId>alfresco-repository</artifactId>
       </dependency>
       <!-- Added a new dependency for Java Mail -->
       <dependency>
           <groupId>com.sun.mail</groupId>
           <artifactId>javax.mail</artifactId>
           <version>1.5.3</version>
       </dependency>
    </dependencies>
    ...
    We can now start implementing some code that uses the Java Mail library.
  3. Update the Hello World Web Script to send an email.

    The implementation can be done as follows in the Java controller (componentX-repo/src/main/java/com/acme/componentX/demoamp/HelloWorldWebScript.java):

    import javax.mail.*;
    import javax.mail.internet.InternetAddress;
    import javax.mail.internet.MimeBodyPart;
    import javax.mail.internet.MimeMessage;
    import javax.mail.internet.MimeMultipart;
    import java.util.HashMap;
    import java.util.Map;
    import java.util.Properties;
    
    /**
    * A demonstration Java controller for the Hello World Web Script.
    *
    * @author martin.bergljung@alfresco.com
    * @since 2.1.0
    */
    public class HelloWorldWebScript extends DeclarativeWebScript {
       protected Map<String, Object> executeImpl(
               WebScriptRequest req, Status status, Cache cache) {
           Map<String, Object> model = new HashMap<String, Object>();
           model.put("fromJava", "HelloFromJava");
           sendEmail();
           return model;
       }
    
       private void sendEmail() {
           String to = "somebody@example.com";
           String subject = "Test email from Web Script";
           String body = "Hello World!";
    
           try {
               // Create mail session
               Properties props = new Properties();
               props.put("mail.smtp.host", "<yourhost>");  // localhost will not work
               props.put("mail.smtp.port", "2525");        // non-privileged port
               Session session = Session.getDefaultInstance(props, null);
               session.setDebug(false);
    
               // Define message
               Message message = new MimeMessage(session);
               String fromAddress = "no-reply@alfresco.com";
               message.setFrom(new InternetAddress(fromAddress));
               message.addRecipient(Message.RecipientType.TO, new InternetAddress(to));
               message.setSubject(subject);
    
               // Create the message part with body text
               BodyPart messageBodyPart = new MimeBodyPart();
               messageBodyPart.setText(body);
               Multipart multipart = new MimeMultipart();
               multipart.addBodyPart(messageBodyPart);
    
               // Put parts in message
               message.setContent(multipart);
    
               // Send the message
               Transport.send(message);
    
           } catch (MessagingException me) {
               me.printStackTrace();
           }
       }
    }
    For the code to work you will need to update <yourhost> to whatever hostname your machine has. The code uses standard Java Mail classes to send a simple email without attachments.
  4. Build the Repository AMP.

    Standing in the Repo AMP project directory, type the following Maven command:

    componentX-repo$ mvn clean install -DskipTests=true
    
    What we end up with now is a Repository AMP with the following JARs:

    This might seem okay at first, but it is actually not a good idea. When we apply this AMP to an Alfresco5.WAR file, the JAR files will be added to the tomcat/webapps/alfresco/WEB-INF/lib directory, and we end up with duplicate Java Mail libraries as it already contains one version of the libarary:

    So the correct approach is to always check what JARs that are available in the Alfresco 5 WAR, and then for any JAR that is available use <scope>provided</scope> when specifying the dependency for it.
  5. Update the Java Mail dependency to have scope provided.

    Open up the componentX-repo/pom.xml and update the Java Mail dependency as follows:

    ...                        
    <dependencies>
       <dependency>
           <groupId>${alfresco.groupId}</groupId>
           <artifactId>alfresco-repository</artifactId>
       </dependency>
    
       <dependency>
           <groupId>com.sun.mail</groupId>
           <artifactId>javax.mail</artifactId>
           <version>1.5.3</version>
           <scope>provided</scope>
       </dependency>
    ...   
    </dependencies>
    This will mean that the Java Mail JAR is not included in the AMP but we can still compile and build against it, which is what we want.

    So to summarize, if the JAR is not in tomcat/webapps/alfresco/WEB-INF/lib, then do not use provided scope as you want it included with the AMP. On the other hand, if the JAR is available, then use provided scope to exclude it from the AMP deliverable.

Adding an internal JAR to a Repository AMP project.

Note: Another requirement that might come up when you are working with a Repository AMP project is that it is growing big, so big that it would make sense to move some AMP project code into its own JAR projects, but still have those part of the same AMP build. Basically turning the Repository AMP project into a multi-module project. So let’s demonstrate how to do this by moving the Hello World Web Script code into its own JAR module and have the AMP dependent on it.
  1. Create a Repository AMP parent project directory.

    To achieve what we want, we will have to turn the Repository AMP project into a multi-module project, and for this we need a parent project. Create a new directory called componentX-parent and then copy the Repository AMP directory into it:

    componentX-repo$ cd ..
    ~/src/$ mkdir componentX-parent
    ~/src/$ mv componentX-repo/ componentX-parent/
  2. Create a Repository AMP parent project POM file.

    Add the following pom.xml to the componentX-parent directory:

    <?xml version="1.0" encoding="UTF-8"?>
    <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
            xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
       <modelVersion>4.0.0</modelVersion>
       <groupId>com.acme</groupId>
       <artifactId>componentX-parent</artifactId>
       <version>1.0-SNAPSHOT</version>
       <name>componentX-repo Repository AMP parent</name>
       <description>This is the parent project for the multi-module componentX-repo Repository AMP project</description>
       <packaging>pom</packaging>
    
       <parent>
           <groupId>org.alfresco.maven</groupId>
           <artifactId>alfresco-sdk-parent</artifactId>
           <version>2.1.0</version>
       </parent>
    
       <modules>
           <module>componentX-repo</module>
       </modules>
    </project>
    Note how this parent project now has the SDK Project as a parent. And it includes the Repository AMP project as a sub-module. The parent project packaging is pom, which means it is not producing an artefact like a JAR, AMP, or WAR, it just acts as a parent for other sub-modules.
  3. Update parent definition in the Repository AMP project POM file.

    Open up the componentX-parent/componentX-repo/pom.xml file. Then update the parent definition as follows:

    <?xml version="1.0" encoding="UTF-8"?>
    <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
            xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
       <modelVersion>4.0.0</modelVersion>
       <artifactId>componentX-repo</artifactId>
       <name>componentX-repo Repository AMP project</name>
       <packaging>amp</packaging>
       <description>Manages the lifecycle of the componentX-repo Repository AMP (Alfresco Module Package)</description>
    
       <parent>
           <groupId>com.acme</groupId>
           <artifactId>componentX-parent</artifactId>
           <version>1.0-SNAPSHOT</version>
       </parent>
       ...
    Note the parent section and how it now points to our new parent. Also, we have removed the version and groupId properties from the AMP project as they are inherited from the parent project.
  4. Build the Repository AMP parent project.

    You should see something like this in the logs:

    componentX-parent$ mvn clean install -DskipTests=true
    . . .
    [INFO] Reactor Summary:
    [INFO]
    [INFO] componentX-repo Repository AMP parent .............. SUCCESS [  0.607 s]
    [INFO] componentX-repo Repository AMP project ............. SUCCESS [  6.850 s]
    [INFO] ------------------------------------------------------------------------
    [INFO] BUILD SUCCESS
    So we now got a parent project that can contain more sub-projects then just the Repository AMP project.
  5. Add a JAR project and move the Hello World Web Script code.

    We are going to create a new JAR sub-project and then move the Hello World Web Script code over to it from the AMP. Let’s start by adding a new JAR project. Stand in the parent directory and issue the following command, which will generate a starting point for a JAR module:

    componentX-parent$ mvn archetype:generate -DgroupId=com.acme -DartifactId=componentX-web-script -DarchetypeArtifactId=maven-archetype-quickstart -DinteractiveMode=false
    We are using the Maven Quickstart archetype to generate the JAR module. Our parent directory now looks like this:
    componentX-parent$ ls -l
    total 16
    drwxrwxr-x 6 martin martin 4096 Jun  5 15:27 componentX-repo
    drwxrwxr-x 3 martin martin 4096 Jun  5 15:35 componentX-web-script
    -rw-rw-r-- 1 martin martin  881 Jun  5 15:35 pom.xml
    When we generate a new module from the parent directory it is automatically added to the modules section of the parent POM as follows:
    ...                        
    <modules>
           <module>componentX-repo</module>
           <module>componentX-web-script</module>
     </modules>
    </project>
    And the parent section is setup correctly also in the new JAR module, open up componentX-parent/componentX-web-script/pom.xml and have a look:
    <?xml version="1.0"?>
    <project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"
            xmlns="http://maven.apache.org/POM/4.0.0"
            xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
       <modelVersion>4.0.0</modelVersion>
    
       <parent>
           <groupId>com.acme</groupId>
           <artifactId>componentX-parent</artifactId>
           <version>1.0-SNAPSHOT</version>
       </parent>
    
       <artifactId>componentX-web-script</artifactId>
      <name>componentX-web-script JAR project</name>
       <url>http://maven.apache.org</url>
       ...
    You might notice that I have removed the version and groupId properties from the JAR project as they are inherited from our parent project. I also updated the name so it is easy to see what type of artefact that is produced.
  6. Build the Repository AMP parent project.

    You should see something like this in the logs:

    componentX-parent$ mvn clean install -DskipTests=true
    . . .
    [INFO] Reactor Summary:
    [INFO]
    [INFO] componentX-repo Repository AMP parent .............. SUCCESS [  0.685 s]
    [INFO] componentX-repo Repository AMP project ............. SUCCESS [  7.131 s]
    [INFO] componentX-web-script JAR project .................. SUCCESS [  0.539 s]
    [INFO] ------------------------------------------------------------------------
    [INFO] BUILD SUCCESS
  7. Move the Hello World Web Script files over to the new JAR project.

    Here we are doing this via command line:

    componentX-parent$ cd componentX-web-script/
    componentX-parent/componentX-web-script$ cd src/main/java/com/acme/
    componentX-parent/componentX-web-script/src/main/java/com/acme$ mkdir componentX
    componentX-parent/componentX-web-script/src/main/java/com/acme$ cd componentX/
    componentX-parent/componentX-web-script/src/main/java/com/acme/componentX$ mkdir demoamp
    componentX-parent/componentX-web-script/src/main/java/com/acme/componentX$ cd demoamp/
    componentX-parent/componentX-web-script/src/main/java/com/acme/componentX/demoamp$ mv ~/src/componentX-parent/componentX-repo/src/main/java/com/acme/componentX/demoamp/HelloWorldWebScript.java .
    componentX-parent/componentX-web-script/src/main/java/com/acme/componentX/demoamp$ cd ../../../../../
    componentX-parent/componentX-web-script/src/main$ mkdir resources
    componentX-parent/componentX-web-script/src/main$ cd resources/
    componentX-parent/componentX-web-script/src/main/resources$ mkdir alfresco
    componentX-parent/componentX-web-script/src/main/resources$ cd alfresco/
    componentX-parent/componentX-web-script/src/main/resources/alfresco$ mkdir extension
    componentX-parent/componentX-web-script/src/main/resources/alfresco$ cd extension/
    componentX-parent/componentX-web-script/src/main/resources/alfresco/extension$ mkdir templates
    componentX-parent/componentX-web-script/src/main/resources/alfresco/extension$ cd templates/
    componentX-parent/componentX-web-script/src/main/resources/alfresco/extension/templates$ mkdir webscripts
    componentX-parent/componentX-web-script/src/main/resources/alfresco/extension/templates$ cd webscripts/
    componentX-parent/componentX-web-script/src/main/resources/alfresco/extension/templates/webscripts$ mv ~/src/componentX-parent/componentX-repo/src/main/amp/config/alfresco/extension/templates/webscripts/* .
    If you have followed along, then you should see something like this in your IDE now:

    We are not moving the spring context file with the Java controller bean definition over to the JAR project as we want there only to be one module bringing in the spring context (i.e. the Repository AMP Module). We are just keeping the Web Script files in a separate JAR to be able to work with them in an easier way. It will also give us the opportunity to completely lift out this JAR as a stand-alone project in the future, and release it separately to Nexus, if we should want to do that.
  8. Move the Java Mail dependency from the AMP project to the JAR project.

    Open up the componentX-parent/componentX-web-script/pom.xml file and update it so it looks like this:

    <?xml version="1.0"?>
    <project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"
            xmlns="http://maven.apache.org/POM/4.0.0"
            xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
       <modelVersion>4.0.0</modelVersion>
    
       <parent>
           <groupId>com.acme</groupId>
           <artifactId>componentX-parent</artifactId>
           <version>1.0-SNAPSHOT</version>
       </parent>
    
       <artifactId>componentX-web-script</artifactId>
       <name>componentX-web-script JAR project</name>
    
       <url>http://maven.apache.org</url>
    
       <dependencies>
           <dependency>
               <groupId>junit</groupId>
               <artifactId>junit</artifactId>
               <version>3.8.1</version>
               <scope>test</scope>
           </dependency>
    
           <dependency>
               <groupId>${alfresco.groupId}</groupId>
               <artifactId>alfresco-repository</artifactId>
           </dependency>
    
           <dependency>
               <groupId>com.sun.mail</groupId>
               <artifactId>javax.mail</artifactId>
               <version>1.5.3</version>
               <scope>provided</scope>
           </dependency>
       </dependencies>
    </project>
    We also needed to add the alfresco-repository dependency as the Java Web Script controller uses Declarative Web Script classes. It does not have version specified as part of dependency definition, so we need to make sure it works anyway.
  9. Move the Dependency Management section from the AMP project to the Parent project.

    Open up the componentX-parent/pom.xml file and update it so it looks like this:

    <?xml version="1.0" encoding="UTF-8"?>
    <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
            xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
       <modelVersion>4.0.0</modelVersion>
       <groupId>com.acme</groupId>
       <artifactId>componentX-parent</artifactId>
       <version>1.0-SNAPSHOT</version>
       <name>componentX-repo Repository AMP parent</name>
       <description>This is the parent project for the multi-module componentX-repo Repository AMP project</description>
       <packaging>pom</packaging>
    
       <parent>
           <groupId>org.alfresco.maven</groupId>
           <artifactId>alfresco-sdk-parent</artifactId>
           <version>2.1.0</version>
       </parent>
    
       <modules>
           <module>componentX-repo</module>
           <module>componentX-web-script</module>
       </modules>
    
       <dependencyManagement>
           <dependencies>
               <dependency>
                   <groupId>${alfresco.groupId}</groupId>
                   <artifactId>alfresco-platform-distribution</artifactId>
                   <version>${alfresco.version}</version>
                   <type>pom</type>
                   <scope>import</scope>
               </dependency>
           </dependencies>
       </dependencyManagement>
    </project>
    It’s a good idea to move the Dependency Management section to the parent POM as you might have more JAR extensions added that needs Alfresco libraries, and then you want to be consitent with what version of these libraries you are using. The Repository AMP POM now looks like this (i.e. componentX-parent/componentX-repo/pom.xml) after removing the Java Mail dependency, moving Dependency Management, and putting in the Web Script JAR dependency:
    <?xml version="1.0" encoding="UTF-8"?>
    <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
            xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
       <modelVersion>4.0.0</modelVersion>
       <groupId>com.acme</groupId>
       <artifactId>componentX-parent</artifactId>
       <version>1.0-SNAPSHOT</version>
       <name>componentX-repo Repository AMP parent</name>
       <description>This is the parent project for the multi-module componentX-repo Repository AMP project</description>
       <packaging>pom</packaging>
    
       <parent>
           <groupId>org.alfresco.maven</groupId>
           <artifactId>alfresco-sdk-parent</artifactId>
           <version>2.1.0</version>
       </parent>
    
       <modules>
           <module>componentX-repo</module>
           <module>componentX-web-script</module>
       </modules>
    
       <dependencyManagement>
           <dependencies>
               <dependency>
                   <groupId>${alfresco.groupId}</groupId>
                   <artifactId>alfresco-platform-distribution</artifactId>
                   <version>${alfresco.version}</version>
                   <type>pom</type>
                   <scope>import</scope>
               </dependency>
           </dependencies>
       </dependencyManagement>
    </project>
    We are now ready to build the project again.
  10. Build the Repository AMP parent project.

    You should see something like this in the logs:

    componentX-parent$ mvn clean install -DskipTests=true
    
    [INFO] Reactor Summary:
    [INFO]
    [INFO] componentX-repo Repository AMP parent .............. SUCCESS [  0.556 s]
    [INFO] componentX-web-script JAR project .................. SUCCESS [  2.662 s]
    [INFO] componentX-repo Repository AMP project ............. SUCCESS [  4.688 s]                
    The Repository AMP now contains the following libraries:

    Now it looks a bit better, we have split up the AMP code into two JARs and the Java Mail dependency is set to provided so no extra libraries are contained in the produced AMP.
  11. Run and try out the Hello World Web Script.

    To make sure this really works we need to try out the Web Script. Step into the AMP directory and do run.sh:

    componentX-parent$ cd componentX-repo/
    componentX-parent/componentX-repo$ chmod +x run.sh
    componentX-parent/componentX-repo$ ./run.sh
    You can test the Web Script as follows from a web browser:

    Remember, if you got the send email code in there, then it will try to send an email. And if you don't have an email server (SMTP) running locally, then the Web Script call will eventually time-out as in the following example:
    2015-06-05 16:43:00,105  INFO  [alfresco.util.OpenOfficeConnectionTester] [DefaultScheduler_Worker-1] The OpenOffice connection was re-established.
     com.sun.mail.util.MailConnectException: Couldn't connect to host, port: brutor, 2525; timeout -1;
      nested exception is:
        java.net.ConnectException: Connection timed out 
We have now seen how external libraries can be used in a Repository AMP project. We have also looked at how to turn the AMP project into a multi-module project to be able to split up the AMP code into multiple JAR extensions.
Parent topic: Advanced Topics [10]

Linking Standard Alfresco AMPs to an AIO project

Some functionality of the Alfresco content management system is delivered as extra modules, such as for example Records Management (RM), Google Docs Integration, and SharePoint Protocol (SPP) Support. This sections goes through how to link such modules to an All-in-One (AIO) project.
This task assumes you completed the Installing and Configuring software [29] section and generated an AIO project as described in this section [57].
You will learn how to link standard Alfresco AMPs to the AIO project so you can use the extra Alfresco functionality that they provide. Most of these modules are implemented with two AMPs. One for server side (Repository) customizations that should be added to the alfresco.war, and one with the custom UI functionality that should be added to the share.war. As an example we will add/link the Records Management (RM) module to the AIO project. It comes implemented in two AMPs.

Linking the RM repository AMP to the alfresco.war.

  1. Add the RM repository AMP dependency.

    In the IDE, open up the alfresco-extensions/acme-cms-poc/repo/pom.xml. Scroll down so you see the dependencies section:

    What you need to do here is uncomment the alfresco-rm dependency, which brings in the RM Repository AMP. Note that dependency type is set to amp, this is because by default Maven dependencies are assumed to be JARs.
  2. Overlaying the RM repository AMP on the alfresco.war.

    The RM repository AMP will not be automatically added to the alfresco.war by just adding the dependency. We need to add some configuration to the war plugin. Scroll further down in the alfresco-extensions/acme-cms-poc/repo/pom.xml file until you see the maven-war-plugin section:

    What you need to do here is uncomment the alfresco-rm overlay, which will overlay the RM repository AMP as the last operation to build the customized alfresco.war.

Linking the RM Share AMP to the share.war.

  1. Add the RM Share AMP dependency.

    In the IDE, open up the alfresco-extensions/acme-cms-poc/share/pom.xml. Scroll down so you see the dependencies section:

    What you need to do here is uncomment the alfresco-rm-share dependency, which brings in the RM Share AMP.
  2. Overlaying the RM Share AMP on the share.war.

    The RM Share AMP will not be automatically added to the share.war by just adding the dependency. We need to add some configuration to the war plugin. Scroll further down in the alfresco-extensions/acme-cms-poc/share/pom.xml file until you see the maven-war-plugin section:

    What you need to do here is uncomment the alfresco-rm-share overlay, which will overlay the RM Share AMP as the last operation to build the customized share.war.

Verify that the AIO project has been configured with the RM module.

  1. Build and Run the AIO project.

    Use the acme-cms-poc/run.sh script to run Alfresco Tomcat with the customized WARs.

  2. Check the logs for installation of RM module.

    2015-05-07 10:30:17,004  INFO  [repo.module.ModuleServiceImpl] [localhost-startStop-1] Found 2 module(s).
    2015-05-07 10:30:17,082  INFO  [repo.module.ModuleServiceImpl] [localhost-startStop-1] Installing module 'org_alfresco_module_rm' version 2.3.
    2015-05-07 10:30:18,560  INFO  [repo.module.ModuleServiceImpl] [localhost-startStop-1] Upgrading module 'repo-amp' version 1.0.1505071028 (was 1.0.1505070918).
    ....
    INFO: Starting ProtocolHandler ["http-bio-8080"]
    
    Note: We can see here that version 2.3 of the RM module has been installed.
  3. Check that the Site Type Records Management is available.

    Login to Share via http://localhost:8080/share and then create a new site. When you create the site select Records Management Site from the Type drop down. If this type is not available then something is not configured correctly, go back and verify that you have followed all the steps correctly.

You have now seen how a standard Alfresco extension module, such as RM, can be brought into the All-in-One project. Other standard modules, such as SPP, can be added in a similar way. Note that some extension modules are implemented in only one AMP. For example, the SPP AMP in the above screen shots is implementing the SharePoint Protocol, which only touches the repository functionality, and so there is only an SPP dependency and overlay in the acme-cms-poc/repo/pom.xml project.
Parent topic: Advanced Topics [10]

Adding more custom AMPs to an AIO project

When you generate an All-in-One project you get one Repository extension AMP (repo-amp) and one Share extension AMP (share-amp). These AMPs are just starting point AMPs, showing you how to create extension AMPs for the Alfresco WAR and Share WAR applications. When the project grows you are likely to want to add more extension modules for different types of functionality.

The are many benefits to this:

  • It will be easier for multiple developers to work in parallel with different modules/functionality as it is not all baked into one big AMP.
  • You can release and tag modules separately, which is really handy as you are not constantly working with SNAPSHOTS in your main AIO project. Meaning you can decide when you want to bring in new functionality.
  • You can very easily do a maintenance release for a specific bit of functionality.
  • It encourages re-use by not having all the extension functionality in one big AMP.
There are two ways to go about this though:
  1. Create new custom AMPs as separate projects outside the AIO project, this is the recommended approach as you get all the benefits listed above.
  2. Create new custom AMPs as part of the AIO project, this does not give all of the above benefits. However, it is useful if you want to split up your extension code and structure it a bit, and you have only a very small team. It is also easier to implement as you don't need access to your own Maven Repository such as Nexus. It does however mean that you will be working with SNAPSHOT dependencies for all AMPs, so it will be difficult to decide when functionality should be included or not in the build. Basically, if the functionality exist in an AMP in the AIO project, it will be included in the build, whether it is complete or not.
  • Creating new stand-alone custom AMPs and linking them to the AIO project [74] This section goes through how to create a new custom Repository AMP project and a new custom Share AMP project and then link those as dependencies in the AIO project.
  • Create new custom AMPs as part of the AIO project [75] This section goes through how to create a new custom Repository AMP project and a new custom Share AMP project and have them added as sub-projects of a multi module AIO project.
Parent topic: Advanced Topics [10]

Creating new stand-alone custom AMPs and linking them to the AIO project

This section goes through how to create a new custom Repository AMP project and a new custom Share AMP project and then link those as dependencies in the AIO project.
This task assumes you completed the Installing and Configuring software [29] section and generated an AIO project as described in this section [57].
You will learn how to create separate AMPs, that are not part of the AIO project, and then how to link those AMPs as dependencies in the AIO project.
Note: If you only need to add a Repository AMP, then skip the steps related to the Share AMP, and vice versa.

Generating a new custom Repository AMP and linking it to the Alfresco.war.

  1. Generate the custom Repository AMP.

    Follow instructions in the create Respository extension project (AMP) [58] section. Give the new Repo AMP a unique artifact id that does not clash with any other ids or the one that is part of the AIO project (i.e. repo-amp). For this example I have used the id component-a-repo. Use the same group id as for the rest of your project artifacts, I'm using com.acme. The AMP is stored in the alfresco-extensions/component-a-repo folder and is not part of the AIO build.

  2. Build and release version 1.0.0 of the Repository AMP. (Optional)

    It is best to avoid SNAPSHOTS when this AMP is included in the All-in-One project. So, use the maven-release-plugin and release and tag the AMP so it is ready to be include in the main AIO project.

    Note: Going through how to configure and setup the maven-release-plugin is out of scope for this article.
  3. Add the custom Repository AMP Dependency

    In the IDE, open up the alfresco-extensions/acme-cms-poc/repo/pom.xml project file. Scroll down so you see the dependencies section. Then add a dependency to component-a-repo:

    Note that dependency for the AMP uses the project.groupId, which is the same as what we used for the custom AMP, com.acme. If you skipped the build and release step (2), then use version 1.0-SNAPSHOT instead.
  4. Overlaying the custom Repository AMP on the alfresco.war

    The Repository AMP will not be automatically added to the alfresco.war by just adding the dependency. We need to add some configuration to the war plugin. Scroll further down in the alfresco-extensions/acme-cms-poc/repo/pom.xml file until you see the maven-war-plugin section. Then add a overlay for the component-a-repo:

  5. Run the AIO project and verify that the new repo module is recognized

    ...                        
    2015-05-07 14:18:44,770  INFO  [repo.module.ModuleServiceImpl] [localhost-startStop-1] Found 2 module(s).
    2015-05-07 14:18:44,791  INFO  [repo.module.ModuleServiceImpl] [localhost-startStop-1] Installing module 'component-a-repo' version 1.0.0.
    2015-05-07 14:18:44,808  INFO  [repo.module.ModuleServiceImpl] [localhost-startStop-1] Installing module 'repo-amp' version 1.0.1505071417.
    ....
    

Generating a new custom Share AMP and adding it to the Share.war.

  1. Generate the custom Share AMP.

    Follow instructions in the create Share extension project (AMP) [76] section. Give the new Share AMP a unique artifact id that does not clash with any other ids or the one that is part of the AIO project (i.e. share-amp). For this example I have used the id component-a-share. Use the same group id as for the rest of your project artifacts, I'm using com.acme. The AMP is stored in the alfresco-extensions/component-a-share folder and is not part of the AIO build.

  2. Build and release version 1.0.0 of the Share AMP. (Optional)

    It is best to avoid SNAPSHOTS when this AMP is included in the All-in-One project. So, use the maven-release-plugin and release and tag the AMP so it is ready to be include in the main AIO project.

    Note: Going through how to configure and set up the maven-release-plugin is out of scope for this article.
  3. Add the custom Share AMP Dependency.

    In the IDE, open up the alfresco-extensions/acme-cms-poc/share/pom.xml project file. Scroll down so you see the dependencies section. Then add a dependency to component-a-share:

    Note that dependency for the AMP uses the project.groupId, which is the same as what we used for the custom AMP, com.acme. If you skipped the build and release step (2), then use version 1.0-SNAPSHOT instead.
  4. Overlaying the custom Share AMP on the share.war

    The Share AMP will not be automatically added to the share.war by just adding the dependency. We need to add some configuration to the war plugin. Scroll further down in the alfresco-extensions/acme-cms-poc/share/pom.xml file until you see the maven-war-plugin section. Then add a overlay for the component-a-share:

  5. There is no logs indicating the AMPs that have been installed on the Alfresco Share web application, so the only way to test is to use whatever custom functionality it is implementing, and see if it works.
You have seen how to build AMP projects separately from the main AIO project, and then how you can incorporate those AMP projects in the main AIO project.
Parent topic: Adding more custom AMPs to an AIO project [69]

Create new custom AMPs as part of the AIO project

This section goes through how to create a new custom Repository AMP project and a new custom Share AMP project and have them added as sub-projects of a multi module AIO project.
This task assumes you completed the Installing and Configuring software [29] section and generated an AIO project as described in this section [57].
You will learn how to create new custom AMPs and have them be part of a multi module AIO project. These AMPs will not be built separately but as part of the AIO project build. And they will be SNAPSHOT references in the AIO project. They will be very similar to the repo-amp and share-amp demo extension projects that comes with the AIO archetype.
Note: If you only need to add a Repository AMP, then skip the steps related to the Share AMP, and vice versa.

Generating a new custom Repository AMP and linking it to the Alfresco.war.

  1. Generate the custom Repository AMP as a sub-module to the AIO parent.

    Follow instructions in the create Respository extension project (AMP) [58] section. Give the new Repo AMP a unique artifact id that does not clash with any other ids or the one that is part of the AIO project (i.e. repo-amp). For this example I have used the id component-a-repo. Use the same group id as for the rest of your project artifacts, I'm using com.acme. The AMP is generated and stored in the alfresco-extensions/acme-cms-poc/component-a-repo folder and is going to be part of the AIO multi module project.

  2. Update parent definition in the Repository AMP pom.xml and remove group and version definition

    By default the Repository AMP will be generated with the SDK Parent set. We need to change it to be the AIO project parent instead. You can grab a parent defintion from one of the other sub-projects, such as the repo-amp project. The alfresco-extensions/acme-cms-poc/component-a-repo/pom.xml file should now start like this:

    <?xml version="1.0" encoding="UTF-8"?>
    <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
             xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
        <modelVersion>4.0.0</modelVersion>
        <artifactId>component-a-repo</artifactId>
        <name>component-a-repo Repository AMP project</name>
        <packaging>amp</packaging>
        <description>Manages the lifecycle of the component-a-repo Repository AMP (Alfresco Module Package)</description>
    
        <parent>
            <groupId>com.acme</groupId>
            <artifactId>acme-cms-poc</artifactId>
            <version>1.0-SNAPSHOT</version>
        </parent>
        ...
    
    You should also remove <groupId> and <version> as these values will be picked up from the AIO parent.
  3. Make sure the new Repository AMP is included as a module in the AIO parent pom.xml

    This should happen automatically when you generate the new project in a sub-directory to the parent AIO project directory. Open up the alfresco-extensions/acme-cms-poc/pom.xml file and verify that the component-a-repo module is there:

    ...
      <modules>
        <module>repo-amp</module>
        <module>share-amp</module>
        <module>repo</module>
        <module>solr-config</module>
        <module>share</module>
        <module>runner</module>
        <module>component-a-repo</module>
      </modules>
    </project>
    
  4. Add the custom Repository AMP Dependency to Alfresco.war project

    In the IDE, open up the alfresco-extensions/acme-cms-poc/repo/pom.xml project file. Scroll down so you see the dependencies section. Then add a dependency to component-a-repo:

    Note that the dependency for the AMP uses the project.groupId, which is what we used for the custom AMP, com.acme. It will also use whatever project.version is currently used.
  5. Overlaying the custom Repository AMP on the alfresco.war

    The Repository AMP will not be automatically added to the alfresco.war by just adding the dependency. We need to add some configuration to the war plugin. Scroll further down in the alfresco-extensions/acme-cms-poc/repo/pom.xml file until you see the maven-war-plugin section. Then add a overlay for the component-a-repo:

  6. Enable the new custom Repository AMP for Rapid Application Development

    To be able to have hot-reloading work for the code that is going to be part of the new component-a-repo AMP, we need to update the virtual webapp context for the Repository webapp (i.e. for the alfresco.war webapp). In the IDE, open up the alfresco-extensions/acme-cms-poc/runner/tomcat/context-repo.xml file. Update the Resource section configuration with the new AMP's resource path:

       <!-- IMPORTANT! The extraResourcePaths string need to be on one continues line -->
        <Resources className="org.apache.naming.resources.VirtualDirContext"
                   extraResourcePaths="/=${project.parent.basedir}/repo-amp/target/repo-amp/web,/=${project.parent.basedir}/component-a-repo/target/component-a-repo/web" />
                            
    And update the Loader section configuration with the new AMP's classpaths:
        <Loader className="org.apache.catalina.loader.VirtualWebappLoader"
                searchVirtualFirst="true"
                virtualClasspath="${project.parent.basedir}/repo-amp/target/classes;
                ${project.parent.basedir}/repo-amp/target/repo-amp/config;
                ${project.parent.basedir}/repo-amp/target/test-classes;
                ${project.parent.basedir}/component-a-repo/target/classes;
                ${project.parent.basedir}/component-a-repo/target/component-a-repo/config;
                ${project.parent.basedir}/component-a-repo/target/test-classes" />
                
    Note: The Tomcat context file located in the alfresco-extensions/acme-cms-poc/component-a-repo/tomcat directory is obsolete when the AMP is contained within an AIO project, it is only used when the AMP is run stand-alone, and it can be deleted.
  7. Start it up and verify that the new AMP is installed

    ...                        
     2015-05-08 13:40:37,688  INFO  [repo.module.ModuleServiceImpl] [localhost-startStop-1] Found 2 module(s).
     2015-05-08 13:40:37,713  INFO  [repo.module.ModuleServiceImpl] [localhost-startStop-1] Upgrading module 'component-a-repo' version 1.0.1505081338 (was 1.0.1505071304).
     2015-05-08 13:40:37,746  INFO  [repo.module.ModuleServiceImpl] [localhost-startStop-1] Upgrading module 'repo-amp' version 1.0.1505081338 (was 1.0.1505081106).
    ...
    

Generating a new custom Share AMP and and linking it to the Share.war.

  1. Generate the custom Share AMP as a sub-module to the AIO parent.

    Follow instructions in the create Share extension project (AMP) [76] section. Give the new Share AMP a unique artifact id that does not clash with any other ids or the one that is part of the AIO project (i.e. share-amp). For this example I have used the id component-a-share. Use the same group id as for the rest of your project artifacts, I'm using com.acme. The AMP is generated and stored in the alfresco-extensions/acme-cms-poc/component-a-share folder and is going to be part of the AIO multi module project.

  2. Update parent definition in the Share AMP pom.xml and remove group and version definition

    By default the Share AMP will be generated with the SDK Parent set. We need to change it to be the AIO project parent instead. You can grab a parent defintion from one of the other sub-projects, such as the share-amp project. The alfresco-extensions/acme-cms-poc/component-a-share/pom.xml file should now start like this:

    <?xml version="1.0" encoding="UTF-8"?>
    <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
             xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
        <modelVersion>4.0.0</modelVersion>
        <artifactId>component-a-share</artifactId>
        <name>component-a-share AMP project</name>
        <packaging>amp</packaging>
        <description>Manages the lifecycle of the component-a-share AMP (Alfresco Module Package)</description>
    
        <parent>
            <groupId>com.acme</groupId>
            <artifactId>acme-cms-poc</artifactId>
            <version>1.0-SNAPSHOT</version>
        </parent>
        ...
    
    You should also remove <groupId> and <version> as these values will be picked up from the AIO parent.
  3. Make sure the new Share AMP is included as a module in the AIO parent pom.xml

    This should happen automatically when you generate the new project in a sub-directory to the parent AIO project directory. Open up the alfresco-extensions/acme-cms-poc/pom.xml file and verify that the component-a-share module is there:

    ...
     <modules>
        <module>repo-amp</module>
        <module>share-amp</module>
        <module>repo</module>
        <module>solr-config</module>
        <module>share</module>
        <module>runner</module>
        <module>component-a-repo</module>
        <module>component-a-share</module>
      </modules>
    </project>
    
  4. Add the custom Share AMP Dependency.

    In the IDE, open up the alfresco-extensions/acme-cms-poc/share/pom.xml project file. Scroll down so you see the dependencies section. Then add a dependency to component-a-share:

    Note that the dependency for the AMP uses the project.groupId, which is what we used for the custom AMP, com.acme. It will also use whatever project.version is currently used.
  5. Overlaying the custom Share AMP on the share.war

    The Share AMP will not be automatically added to the share.war by just adding the dependency. We need to add some configuration to the war plugin. Scroll further down in the alfresco-extensions/acme-cms-poc/share/pom.xml file until you see the maven-war-plugin section. Then add a overlay for the component-a-share:

  6. Enable the new custom Share AMP for Rapid Application Development

    To be able to have hot-reloading work for the code that is going to be part of the new component-a-share AMP, we need to update the virtual webapp context for the Share webapp (i.e. for the share.war webapp). Also, if we don't do this any web resources such as CSS, Images, JS etc located under /web in the AMP will not be available when we use the run profile (this is because during hot reloading we only want them in one place, our project). In the IDE, open up the alfresco-extensions/acme-cms-poc/runner/tomcat/context-share.xml file. Update the Resource section configuration with the new AMP's resource path:

       <!-- IMPORTANT! The extraResourcePaths string need to be on one continues line -->
        <Resources className="org.apache.naming.resources.VirtualDirContext"
                   extraResourcePaths="/=${project.parent.basedir}/share-amp/target/share-amp/web,/=${project.parent.basedir}/component-a-share/target/component-a-share/web" />
                            
    And update the Loader section configuration with the new AMP's classpaths:
        <Loader className="org.apache.catalina.loader.VirtualWebappLoader"
                searchVirtualFirst="true"
                virtualClasspath="${project.parent.basedir}/share-amp/target/classes;
                ${project.parent.basedir}/share-amp/target/share-amp/config;
                ${project.parent.basedir}/share-amp/target/test-classes;
                ${project.parent.basedir}/component-a-share/target/classes;
                ${project.parent.basedir}/component-a-share/target/component-a-share/config;
                ${project.parent.basedir}/component-a-share/target/test-classes;
                ${project.parent.basedir}/share/target/test-classes" />
                
    Note: The Tomcat context file located in the alfresco-extensions/acme-cms-poc/component-a-share/tomcat directory is obsolete when the AMP is contained within an AIO project, it is only used when the AMP is run stand-alone, and it can be deleted.
  7. There is no logs indicating the AMPs that have been installed on the Alfresco Share web application, so the only way to test is to use whatever custom functionality it is implementing, and see if it works.
You have seen how to create new custom AMP projects that should be part of an All-in-One (AIO) project.
Parent topic: Adding more custom AMPs to an AIO project [69]

Upgrading

This section of the documentation walks through how to upgrade your project to use a newer version of Alfresco. It also takes you through the process of upgrading your project to use a newer version of the SDK.
This section is split up into the following areas:
  • Upgrading the Alfresco Product version
  • Upgrading the Alfresco SDK version
  • Upgrading Alfresco Version for an extension project [77] When you have been working with your extension project for a while it is highly likely that there have been some new releases of the Alfresco software. These releases will have new functionality that you might want to take advantage of in your project. It might also be that you are starting to work with this SDK version a while after it has been released, and latest Alfresco version is now newer than what is default in the SDK. This section will walk through how you can upgrade your SDK project to use the newest Alfresco version.
  • Upgrading SDK version for an extension project [78] This section describes how to upgrade the SDK version that is used by your extension project.
Parent topic: Alfresco SDK 2.1 [14]

Upgrading Alfresco Version for an extension project

When you have been working with your extension project for a while it is highly likely that there have been some new releases of the Alfresco software. These releases will have new functionality that you might want to take advantage of in your project. It might also be that you are starting to work with this SDK version a while after it has been released, and latest Alfresco version is now newer than what is default in the SDK. This section will walk through how you can upgrade your SDK project to use the newest Alfresco version.
This task assumes that you have an SDK project to work with, see creating a project [30].
You will learn how to set a new version in all the different kinds of SDK project types.

Upgrading Alfresco version for a Repository AMP project.

  1. Set new version.

    In the IDE, open up the Repository AMP project that you are working on. Then open the project file for it, for example alfresco-extensions/component-a-repo/pom.xml. Scroll down so you see the properties section:

    <properties>
        <!-- The following are default values for data location and Alfresco Community version.
             Uncomment if you need to change (Note. current default version for Enterprise edition is 5.0.1) -->
          <alfresco.version>5.0.e</alfresco.version>
          <!--<alfresco.data.location>alf_data_dev</alfresco.data.location> -->
    
    What you need to do here is uncomment the alfresco.version property, and then update the version to desired latest version. In this case we are upgrading to a newer Community Edition (default is 5.0.d). It would be the same procedure to upgrade to a newer Enterprise version.
  2. Clean metadata and content.

    After setting a newer Alfresco version you will need to clean out current database (with metadata), content files, and indexes. It currently does not work to do an incremental upgrade with the SDK and the H2 database. You can clean the DB and conten files by running the following command: alfresco-extensions/component-a-repo/mvn clean -Ppurge

Upgrading Alfresco version for a Share AMP project.

  1. Set new version.

    In the IDE, open up the Share AMP project that you are working on. Then open the project file for it, for example alfresco-extensions/component-a-share/pom.xml. Scroll down so you see the properties section:

     <properties>
            <!-- The following are default values for data location and Alfresco version.
                 Uncomment if you need to change-->
          <alfresco.version>5.0.e</alfresco.version>
    ...
    
    What you need to do here is uncomment the alfresco.version property, and then update the version to desired latest version. In this case we are upgrading to a newer Community Edition (default is 5.0.d). It would be the same procedure to upgrade to a newer Enterprise version.
  2. Clean metadata and content

    When upgrading the Alfresco Share AMP it is not necessary to clean out a database or clean content because these are related to the Alfresco Repository application (alfresco.war) and not the Share Application (share.war).

Upgrading Alfresco version for an All-in-One (AIO) project.

  1. Set new version.

    In the IDE, open up the All-in-One project that you are working on. Then open the project file for it, for example alfresco-extensions/all-in-one/pom.xml. Scroll down so you see the properties section:

    <properties>
        <!-- The following are default values for data location, Alfresco Community version, and Records Management Module version.
             Uncomment if you need to change (Note. current default version for Enterprise edition is 5.0.1) -->
          <alfresco.version>5.0.e</alfresco.version>
          <alfresco.rm.version>2.3.b</alfresco.rm.version>
              
                        
    What you need to do here is uncomment the alfresco.version property, and then update the version to desired latest version. In this case we are upgrading to a newer Community edition (default is 5.0.d). It would be the same procedure to upgrade to a newer Enterprise edition. Note also that in this case I'm using the Records Management module and I am updating the version for it at the same time by uncommenting the alfresco.rm.version property and setting new version.
  2. Clean metadata and content

    After setting a newer Alfresco version you will need to clean out current database (with metadata), content files, and indexes. It currently does not work to do an incremental upgrade with the SDK and the H2 database. You can clean the DB and conten files by running the following command: alfresco-extensions/component-a-repo/mvn clean -Ppurge

You have now seen how to upgrade the SDK project's Alfresco version and how to clean DB and content before starting with the new version.
Parent topic: Upgrading [11]

Upgrading SDK version for an extension project

This section describes how to upgrade the SDK version that is used by your extension project.

These instructions include information about how to upgrade projects generated from each one of the artifacts. Make sure you are following upgrade instructions for the correct project type and "From version -> To version".

Important: Make sure you have made a complete backup of your project before you start the upgrade process!
  • What changes are allowed in an SDK release? [79] The following describes the kind of changes you can expect (are allowed) in major, minor, and patch releases.
  • Upgrading SDK version from 2.0.0 to 2.1.0 [80] This section contains instructions for how to upgrade an extension project from using SDK version 2.0.0 to using SDK version 2.1.0.
Parent topic: Upgrading [11]

What changes are allowed in an SDK release?

The following describes the kind of changes you can expect (are allowed) in major, minor, and patch releases.

A 3 digit versioning scheme is used, major.minor.patch (e.g. 2.1.0). The following is a list of changes that can go into each one of these releases:

  1. major
    1. Backward incompatible changes (e.g. changes in the archetype project structure, functional changes in archetypes POMs, functional changes in existing profiles)
    2. Changes in the artifact naming
  2. minor Cannot change existing behaviors (e.g. existing profiles semantics, build lifecycle, archetype structure).
    1. New features (e.g. new alfresco-sdk-parent, new archetype profiles, new properties)
    2. New artifacts
  3. patch Ideally no changes to the code of the archetypes.
    1. Bug Fixes
    2. Limited changes to SDK parent and Alfresco Plugin

Note that in addition to this there can be beta releases to give early access to features.

Parent topic: Upgrading SDK version for an extension project [78]

Upgrading SDK version from 2.0.0 to 2.1.0

This section contains instructions for how to upgrade an extension project from using SDK version 2.0.0 to using SDK version 2.1.0.

These instructions include information about how to upgrade projects generated from each one of the Maven artifacts. Make sure you are following upgrade instructions for the correct project type.

Important: Make sure you have made a complete backup of your project before you start the upgrade process!
  • Upgrading a Repository AMP project from SDK 2.0.0 to 2.1.0 [81] These instructions will walk through what is needed when upgrading a Repository AMP project from using SDK version 2.0.0 to using SDK version 2.1.0.
  • Upgrading a Share AMP project from SDK 2.0.0 to 2.1.0 [82] These instructions will walk through what is needed when upgrading a Share AMP project from using SDK version 2.0.0 to using SDK version 2.1.0.
  • Upgrading an All-in-One (AIO) project from SDK 2.0.0 to 2.1.0 [83] These instructions will walk through what is needed when upgrading an AIO project from using SDK version 2.0.0 to using SDK version 2.1.0.
Parent topic: Upgrading SDK version for an extension project [78]

Upgrading a Repository AMP project from SDK 2.0.0 to 2.1.0

These instructions will walk through what is needed when upgrading a Repository AMP project from using SDK version 2.0.0 to using SDK version 2.1.0.
There are multiple ways to go about an SDK upgrade. These instructions assume that you have a Repository AMP project where the source code is managed by a Software Configuration Management (SCM) system such as Git or Subversion. And you cannot just through away the history of this project, you need to upgrade "in-place". On the other hand, if your project is small, and you don't mind starting with a new project in the SCM, it might be easier to just generate a new project [58] from the Repository AMP 2.1.0 SDK archetype and move the code and other changes over to it from the SDK 2.0.0 project, but this method is not covered in this article.
Note: In the following instructions the REPO_AMP_PROJECT_PATH variable denotes the path to where you have your Repository AMP project folder. So, for example, if your Repository AMP project was generated in the C:\alfresco-extensions\acme-repo-amp directory, then this directory path is the value of this variabel.
Important: Make sure you have made a complete backup of your project before you start the upgrade process!
  1. Setting the SDK Version to 2.1.0.

    In the IDE, open up the {REPO_AMP_PROJECT_PATH}/pom.xml project file. Scroll down so you see the parent section. Then update it to look as follows:

    <parent>
        <groupId>org.alfresco.maven</groupId>
        <artifactId>alfresco-sdk-parent</artifactId>
        <version>2.1.0</version>
    </parent>
  2. Remove the property used to specify the webapp path for Alfresco Repository web application.

    In the project file {REPO_AMP_PROJECT_PATH}/pom.xml scroll down to the properties section. Then remove the property called alfresco.client.contextPath. This property is already set to /alfresco in the SDK parent POM so no need to set it here.

  3. Add the amp-to-war profile with rad dependency.

    In the IDE, open up the {REPO_AMP_PROJECT_PATH}/pom.xml project file. Scroll down so you see the profiles section. Then add the following profile to it:

        <!--
            If the 'amp-to-war' profile is enabled then make sure to bring in the alfresco-rad module,
            which has the H2 scripts and other RAD features.
            -->
        <profile>
            <id>amp-to-war</id>
            <dependencies>
                <dependency>
                    <groupId>org.alfresco.maven</groupId>
                    <artifactId>alfresco-rad</artifactId>
                    <version>${maven.alfresco.version}</version>
                </dependency>
            </dependencies>
        </profile>
  4. Update the Tomcat virtual webapp context file.

    Open the {REPO_AMP_PROJECT_PATH}/tomcat/context.xml file. Change it to look like this for best RAD experience:

    <?xml version="1.0" encoding="UTF-8"?>
    <!-- ===================================================================================================================
        This context file is used only in a development IDE for rapid development,
        it is never released with the Alfresco.war
        =================================================================================================================-->
    
    <!-- Setup docBase to something like repo-amp/target/repo-amp-war
         and path to /alfresco
         The Alfresco.war 5.0 does not have a webapp (it used to have Alfresco Explorer but not anymore)
         that we will access, so this docBase might not be needed
    -->
    <Context docBase="${app.amp.client.war.folder}" path="${alfresco.client.contextPath}">
    
      <Resources className="org.apache.naming.resources.VirtualDirContext"
                 extraResourcePaths="/=${project.build.directory}/${project.build.finalName}/web" />
    
      <!-- Setup the virtual class path like this:
           1) target/classes
           2) target/${project.build.finalName}/config
           3) target/test-classes
    
           This way mvn compile can be invoked and all changes will be picked up
      -->
      <Loader searchVirtualFirst="true"
              className="org.apache.catalina.loader.VirtualWebappLoader"
              virtualClasspath="${project.build.outputDirectory};${project.build.directory}/${project.build.finalName}/config;${project.build.testOutputDirectory}" />
    
    
      <!-- This enables hot reloading of web resources from uncompressed jars (while in prod they would be loaded from  WEB-INF/lib/{\*.jar}/META-INF/resources -->
      <JarScanner scanAllDirectories="true" />
    </Context>
    
  5. Replace run scripts.

    Version 2.1.0 of the SDK have changes to the Linux run scripts and have new run scripts for Windows. So it make sense to take the new scripts from a newly generated 2.1.0 Repository AMP project and replace the 2.0.0 scripts with them. So follow these instructions [58] to generate a Repository AMP project based on the 2.1.0 archetype. Then just copy over the {newly generated 2.1.0 Repo AMP}/run.* scripts to the {REPO_AMP_PROJECT_PATH} directory, overwriting the run.sh script.

Your Repository AMP project should now be fully updated to use the 2.1.0 version of the SDK.
Parent topic: Upgrading SDK version from 2.0.0 to 2.1.0 [80]

Upgrading a Share AMP project from SDK 2.0.0 to 2.1.0

These instructions will walk through what is needed when upgrading a Share AMP project from using SDK version 2.0.0 to using SDK version 2.1.0.
There are multiple ways to go about an SDK upgrade. These instructions assume that you have a Share AMP project where the source code is managed by a Software Configuration Management (SCM) system such as Git or Subversion. And you cannot just through away the history of this project, you need to upgrade "in-place". On the other hand, if your project is small, and you don't mind starting with a new project in the SCM, it might be easier to just generate a new project [76] from the Share AMP 2.1.0 SDK archetype and move the code and other changes over to it from the SDK 2.0.0 project, but this method is not covered in this article.
Note: In the following instructions the SHARE_AMP_PROJECT_PATH variable denotes the path to where you have your Share AMP project folder. So, for example, if your Share AMP project was generated in the C:\alfresco-extensions\acme-share-amp directory, then this directory path is the value of this variabel.
Important: Make sure you have made a complete backup of your project before you start the upgrade process!
  1. Setting the SDK Version to 2.1.0.

    In the IDE, open up the {SHARE_AMP_PROJECT_PATH}/pom.xml project file. Scroll down so you see the parent section. Then update it to look as follows:

    <parent>
        <groupId>org.alfresco.maven</groupId>
        <artifactId>alfresco-sdk-parent</artifactId>
        <version>2.1.0</version>
    </parent>
  2. Remove the property used to specify the webapp path for the Alfresco Share web application.

    In the project file {SHARE_AMP_PROJECT_PATH}/pom.xml scroll down to the properties section. Then remove the property called alfresco.client.contextPath. This property is now called share.client.contextPath, and it is already set to /share in the SDK parent POM, so no need to set it here.

  3. Update the name of the property specifying Share Webapp aritifact ID.

    In the project file {SHARE_AMP_PROJECT_PATH}/pom.xml scroll down to the properties section. Then change the name of the property called alfresco.client.war to app.amp.client.war.artifactId.

  4. Add a build section to enable the JS Compression plugin.

    In the same project file {SHARE_AMP_PROJECT_PATH}/pom.xml scroll down to the dependencies end tag. Then add the following build section after it with the yuicompressor-maven-plugin to enable JS compression:

    . . .                        
    </dependencies>
    
    <build>
        <plugins>
            <!-- Compress JavaScript files and store as *-min.js -->
            <plugin>
                <groupId>net.alchim31.maven</groupId>
                <artifactId>yuicompressor-maven-plugin</artifactId>
            </plugin>
        </plugins>
    </build>
  5. Update share-config-custom.xml to enable better RAD.

    Open the {SHARE_AMP_PROJECT_PATH}/src/test/resources/alfresco/web-extension/share-config-custom.xml file and update the web-framework configuration so it looks like this:

    <web-framework>
        <autowire>
            <!-- Changing this to 'development' currently breaks the Admin Console.
                 Instead we make a POST to clear Share dependency caches, see 'clear-caches-refresh-ws' profile. -->
            <mode>production</mode> <!-- not really need in the long run, used for YUI - deprecate -->
        </autowire>
    
        <!--
             We don't need to do this when we have the new refresh mojos in the Alfresco plug-in.
    
             If resource caching has been disabled then all the dependency caches will be cleared
             before processing the Aikau jsonModel request...
                (i.e. this.dojoDependencyHandler.clearCaches() )
    
             For more information see the Aikau source code: https://github.com/Alfresco/Aikau
        -->
        <disable-resource-caching>false</disable-resource-caching>
    </web-framework>
    
  6. Update the Tomcat virtual webapp context file.

    Open the {SHARE_AMP_PROJECT_PATH}/tomcat/context.xml file. Change it to look like this for best RAD experience:

    <?xml version="1.0" encoding="UTF-8"?>
    <!-- ===================================================================================================================
        This context file is used only in a development IDE for rapid development,
        it is never released with the Alfresco.war
        =================================================================================================================-->
    
    <!-- Setup docBase to something like share-amp/target/share-amp-war
         and path to /share -->
    <Context docBase="${app.amp.client.war.folder}" path="${share.client.contextPath}">
    
      <Resources className="org.apache.naming.resources.VirtualDirContext"
        extraResourcePaths="/=${project.build.directory}/${project.build.finalName}/web" />
    
      <!-- Configure where the Share (share.war) web application can load classes, test classes, and config -->
      <!-- Setup the virtual class path like this:
           1) target/classes
           2) target/${project.build.finalName}/config
           3) target/test-classes
    
           This way mvn compile can be invoked and all changes will be picked up
      -->
      <Loader searchVirtualFirst="true"
              className="org.apache.catalina.loader.VirtualWebappLoader"
              virtualClasspath="${project.build.outputDirectory};${project.build.directory}/${project.build.finalName}/config;${project.build.testOutputDirectory}" />
    
      <!-- This enables hot reloading of web resources from uncompressed jars (while in prod they would be loaded from  WEB-INF/lib/{\*.jar}/META-INF/resources -->
      <JarScanner scanAllDirectories="true" />
      
    </Context>
    
  7. Replace run scripts.

    Version 2.1.0 of the SDK have changes to the Linux run scripts and have new run scripts for Windows. So it make sense to take the new scripts from a newly generated 2.1.0 Share AMP project and replace the 2.0.0 scripts with them. So follow these instructions [76] to generate a Share AMP project based on the 2.1.0 archetype. Then just copy over the {newly generated 2.1.0 Share AMP}/run.* scripts to the {SHARE_AMP_PROJECT_PATH} directory, overwriting the run.sh script.

Your Share AMP project should now be fully updated to use the 2.1.0 version of the SDK.
Parent topic: Upgrading SDK version from 2.0.0 to 2.1.0 [80]

Upgrading an All-in-One (AIO) project from SDK 2.0.0 to 2.1.0

These instructions will walk through what is needed when upgrading an AIO project from using SDK version 2.0.0 to using SDK version 2.1.0.
There are multiple ways to go about an SDK upgrade. These instructions assume that you have an All-in-One project where the source code is managed by a Software Configuration Management (SCM) system such as Git or Subversion. And you cannot just through away the history of this project, you need to upgrade "in-place". On the other hand, if your project is small, and you don't mind starting with a new project in the SCM, it might be easier to just generate a new project [57] from the AIO 2.1.0 SDK archetype and move the code and other changes over to it from the SDK 2.0.0 project, but this method is not covered in this article.
Note: In the following instructions the AIO_PROJECT_PATH variable denotes the path to where you have your All-in-One top project folder. So, for example, if your All-in-One project was generated in the C:\alfresco-extensions\acme-poc directory, then this directory path is the value of this variabel.
Important: Make sure you have made a complete backup of your project before you start the upgrade process!

Update the top AIO project file.

  1. Setting the SDK Version to 2.1.0.

    In the IDE, open up the {AIO_PROJECT_PATH}/pom.xml project file. Scroll down so you see the parent section. Then update it to look as follows:

    <parent>
        <groupId>org.alfresco.maven</groupId>
        <artifactId>alfresco-sdk-parent</artifactId>
        <version>2.1.0</version>
    </parent>
  2. Add a new property for the Alfresco Share Webapp location.

    In the same project file {AIO_PROJECT_PATH}/pom.xml scroll down to the properties section. Then update it with this extra property:

    <properties>
    . . .
        <!-- The Alfresco Share web application is accessible via this URL -->
        <share.client.url>http://localhost:8080/share</share.client.url>
            
  3. Add a new property for the Alfresco RM Module version (OPTIONAL).

    If the Records Management (RM) module is used then add a property specifying the RM version that should be used. In the properties section add this extra property:

    <properties>
    . . .
        <alfresco.rm.version>2.3</alfresco.rm.version>
            
  4. Add a build section to enable some plugins.

    In the same project file {AIO_PROJECT_PATH}/pom.xml scroll down to the dependencyManagement end tag. Then add the following build section after it with the yuicompressor-maven-plugin to enable JS compression and the alfresco-maven-plugin to enable webapp RAD development:

    . . .                        
    </dependencyManagement>
    
    <build>
        <plugins>
            <!-- Compress JavaScript files and store as *-min.js -->
            <plugin>
                <groupId>net.alchim31.maven</groupId>
                <artifactId>yuicompressor-maven-plugin</artifactId>
            </plugin>
            <plugin>
                <groupId>org.alfresco.maven.plugin</groupId>
                <artifactId>alfresco-maven-plugin</artifactId>
            </plugin>
        </plugins>
    </build>
  5. Remove the Records Management (RM) profile.

    In the same project file {AIO_PROJECT_PATH}/pom.xml scroll down to the profiles section. Then remove the profile with the rm id (identifier). The RM module is added via the {AIO_PROJECT_PATH}/repo/pom.xml and the {AIO_PROJECT_PATH}/share/pom.xml project files. See further down in these instructions for more information.

  6. Update the name of the Solr module.

    SDK version 2.1.0 comes with support for Solr4, which is deployed directly from the maven artefact. The maven module just contains Solr 4 configuration information and because of this has changed name from solr to solr-config, so we need to update to the new name. In the same project file {AIO_PROJECT_PATH}/pom.xml scroll down to the modules section. Update it so it looks like this:

    . . .                        
    <modules>
        <module>repo-amp</module>
        <module>share-amp</module>
        <module>repo</module>
        <module>solr-config</module>
        <module>share</module>
        <module>runner</module>
    </modules>
    Note. You might have added extra modules that are not part of the AIO artefact, don't remove these modules from the definition.

Update the Repository Webapp (alfresco.war) Project file

  1. Remove the Records Management (RM) profile.

    In the project file {AIO_PROJECT_PATH}/repo/pom.xml scroll down to the profiles section. Then remove the profile with the rm id (identifier). The RM module is now instead added permanently as a dependency and overlay.

  2. Add a Records Management (RM) Module Dependency to Repository WAR (OPTIONAL)

    If the RM module is used, then it is now added permanently to the project instead of via profile activation. Add a dependency for it as follows. In the IDE, open up the {AIO_PROJECT_PATH}/repo/pom.xml project file. Scroll down so you see the dependencies section. Then add the following dependency:

    <dependencies>
    . . . 
        <dependency>
            <groupId>${alfresco.groupId}</groupId>
            <artifactId>alfresco-rm</artifactId>
            <version>${alfresco.rm.version}</version>
            <type>amp</type>
        </dependency>
  3. Add a Records Management (RM) Module Overlay Repository WAR (OPTIONAL)

    If the RM module is used, then it is now added permanently to the project instead of via profile activation. Add an overlay configuration as follows. In the {AIO_PROJECT_PATH}/repo/pom.xml project file scroll down so you see the overlays section. Then add the following overlay at the end:

    <overlays>
    . . . 
        <overlay>
            <groupId>${alfresco.groupId}</groupId>
            <artifactId>alfresco-rm</artifactId>
            <type>amp</type>
        </overlay>
    </overlays>
  4. Make sure the Repository is using the Solr4 subsystem

    When running all the web applictions during testing the repository webapp (alfresco.war) is reading its configuration from the {AIO_PROJECT_PATH}/repo/src/main/properties/local/alfresco-global.properties file. We need to update it so it uses Solr4, the following properties should be changed:

    index.subsystem.name=solr4
    solr.backup.alfresco.remoteBackupLocation=${dir.root}/solr4Backup/alfresco
    solr.backup.archive.remoteBackupLocation=${dir.root}/solr4Backup/archive
    

Update the Repository AMP Project file

  1. Remove the property used to specify the artifact ID for the Alfresco WAR.

    In the project file {AIO_PROJECT_PATH}/repo-amp/pom.xml scroll down to the properties section. Then remove the property called alfresco.client.war. This property is now called app.amp.client.war.artifactId and defaults to alfresco, so no need to set it in the repo-amp project file. This property is used when you run with the -Pamp-to-war profile.

  2. Add a Records Management (RM) classes Dependency (OPTIONAL)

    If the RM module is used, then it is now added permanently to the project instead of via profile activation. So to get access to the RM classes add a dependency as follows. In the {AIO_PROJECT_PATH}/repo-amp/pom.xml project file scroll down so you see the dependencies section. Then add the following dependency:

    <dependencies>
    . . . 
        <dependency>
            <groupId>${alfresco.groupId}</groupId>
            <artifactId>alfresco-rm</artifactId>
            <version>${alfresco.rm.version}</version>
            <classifier>classes</classifier>
        </dependency>
  3. Remove the Records Management (RM) profile.

    In the project file {AIO_PROJECT_PATH}/repo-amp/pom.xml scroll down to the profiles section. Then remove the profile with the rm id (identifier). The RM classes are now instead added permanently as a dependency.

Update the Share Webapp (share.war) Project file

  1. Add a properties section with a new property for the Alfresco Repository location.

    In the project file {AIO_PROJECT_PATH}/share/pom.xml add the following properties section just after the parent section:

    . . .
    </parent>
    
    <properties>
       <!-- Used in share-config-custom.xml when testing.
            By default points to standard location (local) of Alfresco Repository -->
       <alfresco.repo.url>http://localhost:8080/alfresco</alfresco.repo.url>
    </properties>
  2. Move share-config-custom.xml from share-amp to share.

    The share configuration file has moved from the share AMP sub project to the share WAR project. This is because it contains generic configuration such as where the Repository is running and RAD related configuration. Move the {AIO_PROJECT_PATH}/share-amp/src/test/resources/alfresco/web-extension/share-config-custom.xml file to the {AIO_PROJECT_PATH}/share/src/main/resources/alfresco/web-extension location. Then update the web-framework configuration so it looks like this:

    <web-framework>
        <autowire>
            <!-- Changing this to 'development' currently breaks the Admin Console.
            Instead we make a POST to clear Share dependency caches, see 'clear-caches-refresh-ws' profile. -->
            <mode>production</mode> <!-- not really need in the long run, used for YUI - deprecate -->
        </autowire>
        
        <!--
            We don't need to do this when we have the new refresh mojos in the Alfresco plug-in.
            
            If resource caching has been disabled then all the dependency caches will be cleared
            before processing the Aikau jsonModel request...
            (i.e. this.dojoDependencyHandler.clearCaches() )
            
            For more information see the Aikau source code: https://github.com/Alfresco/Aikau
        -->
        <disable-resource-caching>false</disable-resource-caching>
    </web-framework>
    
  3. Remove the Records Management (RM) profile.

    In the project file {AIO_PROJECT_PATH}/share/pom.xml scroll down to the profiles section. Then remove the profile with the rm id (identifier). The RM module is now instead added permanently as a dependency and overlay.

  4. Add a Records Management (RM) Module Dependency to Share WAR (OPTIONAL)

    If the RM module is used, then it is now added permanently to the project instead of via profile activation. Add a dependency for it as follows. In the IDE, open up the {AIO_PROJECT_PATH}/share/pom.xml project file. Scroll down so you see the dependencies section. Then add the following dependency:

    <dependencies>
    . . . 
        <dependency>
            <groupId>${alfresco.groupId}</groupId>
            <artifactId>alfresco-rm-share</artifactId>
            <version>${alfresco.rm.version}</version>
            <type>amp</type>
        </dependency>
  5. Add a Records Management (RM) Module Overlay to Share WAR (OPTIONAL)

    If the RM module is used, then it is now added permanently to the project instead of via profile activation. Add an overlay configuration as follows. In the {AIO_PROJECT_PATH}/share/pom.xml project file scroll down so you see the overlays section. Then add the following overlay at the end:

    <overlays>
    . . . 
        <overlay>
            <groupId>${alfresco.groupId}</groupId>
            <artifactId>alfresco-rm-share</artifactId>
            <type>amp</type>
        </overlay>
    </overlays>

Update the Share AMP Project file

  1. Change the name of the property used to specify the artifact ID for the Share WAR.

    In the project file {AIO_PROJECT_PATH}/share-amp/pom.xml scroll down to the properties section. Then change the name of property called alfresco.client.war to its new name app.amp.client.war.artifactId. It defaults to alfresco so we need to override it here with the value share. This property is used when you run with the -Pamp-to-war profile.

  2. Remove the property used to specify the location of the Alfresco Repository Webapp.

    In the project file {AIO_PROJECT_PATH}/share-amp/pom.xml scroll down to the properties section. Then remove the property called alfresco.repo.url. This property is only used by the {AIO_PROJECT_PATH}/share/pom.xml project in an All-in-One extension project.

  3. Remove the property used to specify the port number for embedded Tomcat.

    In the project file {AIO_PROJECT_PATH}/share-amp/pom.xml scroll down to the properties section. Then remove the property called maven.tomcat.port. This property is only used by the {AIO_PROJECT_PATH}/runner/pom.xml project when starting an embeeded Tomcat instance. Default port number is configured to 8080 in the parent SDK pom.

  4. Add dependencies for TestNG and Share Page Object classes.

    In version 2.1.0 of the SDK there are two new profiles called regression-testing and functional-testing that uses Page Objects (PO) to do functional testing of the Share Web application. We need to add all dependencies needed for these tests. In the {AIO_PROJECT_PATH}/share-amp/pom.xml project file scroll down so you see the dependencies section. Then add the following dependencies:

    <dependencies>
    . . . 
         <!--===============================================================
            The following dependencies are needed to be able to compile the
            custom functional tests that are based on Page Objects (PO)
            ===============================================================-->
    
        <!-- Bring in the Share Page Objects (PO) used in our functional tests.
             It contains page objects such as LoginPage -->
        <dependency>
            <groupId>${alfresco.groupId}</groupId>
            <artifactId>share-po</artifactId>
            <version>${alfresco.version}</version>
            <scope>test</scope>
        </dependency>
        <!-- Bring in the Share Page Object (PO) Tests that comes with Alfresco. It has
             the org.alfresco.po.share.AbstractTest class that our custom tests extend. -->
        <dependency>
            <groupId>${alfresco.groupId}</groupId>
            <artifactId>share-po</artifactId>
            <version>${alfresco.version}</version>
            <classifier>tests</classifier>
            <scope>test</scope>
    
            <!-- Exclude version 2.39.0 of selenium that does not work with latest FF browsers, we include
               version 2.45 later on here -->
            <exclusions>
                <exclusion>
                    <groupId>org.seleniumhq.selenium</groupId>
                    <artifactId>selenium-java</artifactId>
                </exclusion>
                <exclusion>
                    <groupId>org.seleniumhq.selenium</groupId>
                    <artifactId>selenium-server</artifactId>
                </exclusion>
            </exclusions>
        </dependency>
        <!-- Bring in newer selenium version -->
        <dependency>
            <groupId>org.seleniumhq.selenium</groupId>
            <artifactId>selenium-java</artifactId>
            <version>2.45.0-alfresco</version>
        </dependency>
        <!-- Test NG is defined with test scope in share-po, so need it here too -->
        <!-- Alfresco code creates a wrapper around Test NG -->
        <dependency>
            <groupId>org.alfresco.test</groupId>
            <artifactId>alfresco-testng</artifactId>
            <version>1.1</version>
            <scope>test</scope>
            <exclusions>
                <exclusion>
                    <groupId>org.hamcrest</groupId>
                    <artifactId>hamcrest-core</artifactId>
                </exclusion>
            </exclusions>
        </dependency>
    
    </dependencies>

Replace Modules and Scripts

  1. Replace the runner module.

    The project configuration for the runner module has changed quite a bit in version 2.1.0 of the SDK. And there should not be much custom configuration done to it. So it make sense to take the runner module from a newly generated 2.1.0 AIO project and replace the 2.0.0 runner module with it. So follow these instructions [57] to generate an AIO project based on the 2.1.0 archetype. Then delete the {AIO_PROJECT_PATH}/runner module/directory from the All-in-One project. Now copy the {newly generated 2.1.0 AIO}/runner module into the {AIO_PROJECT_PATH}/runner location.

    The new runner module probably does not have the same parent configuration as your {AIO_PROJECT_PATH} project. So open up the {AIO_PROJECT_PATH}/runner/pom.xml file and make sure the parent section is correct.

    If you have made changes to the virtual web application context because you have added more AMPs to the AIO project, then see these instructions [84] for how to update the 2.1.0 runner context.

  2. Replace the solr module.

    The project configuration for the solr module has changed completely from bringing in the complete Solr 1.4 web application to just bringing in the Solr4 configuration. So it make sense to take the solr-config module from a newly generated 2.1.0 AIO project and replace the 2.0.0 solr module with it. So follow these instructions [57] to generate an AIO project based on the 2.1.0 archetype (if you have not already done it). Then delete the {AIO_PROJECT_PATH}/solr module/directory from the All-in-One project. Now copy the {newly generated 2.1.0 AIO}/solr-config module into the {AIO_PROJECT_PATH}/solr-config location.

    The new solr-config module probably does not have the same parent configuration as your {AIO_PROJECT_PATH} project. So open up the {AIO_PROJECT_PATH}/solr-config/pom.xml file and make sure the parent section is correct.

    If you have made changes to the Solr configuration, such as adding a synonyms list, then you will have to update the solr-config project with these changes.

  3. Replace run scripts.

    Version 2.1.0 of the SDK have changes to the Linux run scripts and have new run scripts for Windows. So it make sense to take the new scripts from a newly generated 2.1.0 AIO project and replace the 2.0.0 scripts with them. So follow these instructions [57] to generate an AIO project based on the 2.1.0 archetype (if you have not already done it). Then just copy over the {newly generated 2.1.0 AIO}/run.* scripts to the {AIO_PROJECT_PATH} directory, overwriting the run.sh script.

Your All-in-One project should now be fully updated to use the 2.1.0 version of the SDK.
Parent topic: Upgrading SDK version from 2.0.0 to 2.1.0 [80]

Using MySQL

The Alfresco SDK can be configured to use a MySQL database server rather than the default option of the H2 database engine.

By default, the Alfresco SDK uses H2 as its database, but it can be configured to use other databases such as MySQL, PostgreSQL, or DB2. MySQL [85] is a commonly used open source database. The following tutorials looks at how the Alfresco SDK can be configured to use MySQL rather than H2 as the main database for Alfresco, for both Repository AMP projects and All-in-One projects.

  • Using MySQL with a repository AMP project [86] The Alfresco SDK can be configured to use MySQL, rather than the default database which is H2. The following shows how to configure a repository AMP project to use MySQL.
  • Using MySQL with an All-in-One project [87] The Alfresco SDK can be configured to use MySQL, rather than the default database which is H2. The following shows how to configure an All-in-One project to use MySQL.
Parent topic: Alfresco SDK 2.1 [14]

Using MySQL with a repository AMP project

The Alfresco SDK can be configured to use MySQL, rather than the default database which is H2. The following shows how to configure a repository AMP project to use MySQL.
This tutorial assumes you have access to a suitable MySQL server, or a local installation of MySQL. Instructions on how to do this can be found in the MySQL documentation [88]. It is also assumed that you have created a repository AMP project according to instructions found here [58].
You will see how to configure Alfresco SDK to use MySQL, rather than H2. This involves running a simple script in MySQL, to create the necessary database and user, and set privileges. You will also need to add some configuration to the AMP project pom.xml file.
  1. Create a file db_setup.sql with the following contents:

                            
        create database alfresco default character set utf8;
        grant all on alfresco.* to 'alfresco'@'localhost' identified by 'alfresco' with grant option;
        grant all on alfresco.* to 'alfresco'@'localhost.localdomain' identified by 'alfresco' with grant option;                        
                            
                        
  2. Log into your MySQL server as root using the MySQL client:

                            
        mysql -u root -p                        
                            
                        
  3. Run your script to set up the database for Alfresco:

                            
        source db_setup.sql                        
                            
                        

    This will create the Alfresco database (alfresco) and user/pwd (alfresco/alfresco).

  4. You now need to configure your project POM file. Change into your project directory and load pom.xml into your editor of choice.
  5. Add a dependency for the MySQL JDBC driver at the <project> level of your pom.xml file:

        
        <dependencies>
            ...
            <dependency>
                <groupId>mysql</groupId>
                <artifactId>mysql-connector-java</artifactId>
                <version>5.1.32</version>
            </dependency>
        </dependencies>
    
                        
  6. Now add the configuration required for connecting to your MySQL server in the properties section of the POM:

                            
            <!-- MySQL configuration -->
            <alfresco.db.name>alfresco</alfresco.db.name>
            <alfresco.db.username>alfresco</alfresco.db.username>
            <alfresco.db.password>alfresco</alfresco.db.password>
            <alfresco.db.host>localhost</alfresco.db.host>
            <alfresco.db.port>3306</alfresco.db.port>
            <alfresco.db.params></alfresco.db.params>
            <alfresco.db.url>jdbc:mysql://${alfresco.db.host}:${alfresco.db.port}/${alfresco.db.name}</alfresco.db.url>
            <alfresco.db.datasource.class>org.gjt.mm.mysql.Driver</alfresco.db.datasource.class>                        
                            
                        
  7. Save your changes to the pom.xml file.
  8. Comment out the H2 Dialect configuration from alfresco-global.properties

    Open the src/test/properties/local/alfresco-global.properties configuration file. Then comment out the following line:

                            
    #hibernate.dialect=org.hibernate.dialect.H2Dialect                      
    
  9. Now in the project directory you can type:

                            
        mvn clean install                        
                            
                        
  10. Clean up any previous runs with H2:

                            
        rm -rf alf_data_dev/                        
                            
                        
    This step is also very important as it will remove any content and indexes created when you started with the H2 database. When you switch over to run with MySQL the system thinks that it is the first time that you are running Alfresco, so it will create a new database, new content, and index again, which will clash with any previous starts with H2.
  11. Once you have a successful build you can run up Alfresco using:

                            
        mvn install -Pamp-to-war                        
                            
                        

    Alfresco will start up and use the MySQL database server that you configured. Track console messages to confirm such as:

                            
    ...
    2014-09-15 15:47:52,552  INFO  [alfresco.repo.admin] [localhost-startStop-1] Using database URL 'jdbc:mysql://localhost:3306/alfresco' with user 'alfresco'.
    2014-09-15 15:47:52,987  INFO  [alfresco.repo.admin] [localhost-startStop-1] Connected to database MySQL version 5.6.11                
    ...
    
                        
  12. Check for the message INFO: Starting ProtocolHandler ["http-bio-8080"].
  13. Point your web browser at http://localhost:8080/alfresco, and log in as admin with password admin.
You have configured the Alfresco SDK to use MySQL rather than H2.
Parent topic: Using MySQL [12]

Using MySQL with an All-in-One project

The Alfresco SDK can be configured to use MySQL, rather than the default database which is H2. The following shows how to configure an All-in-One project to use MySQL.
This tutorial assumes you have access to a suitable MySQL server, or a local installation of MySQL. Instructions on how to do this can be found in the MySQL documentation [88].
You will see how to configure Alfresco SDK to use MySQL, rather than H2. This involves running a simple script in MySQL, to create the necessary database and user, and set privileges. You will also need to add some configuration to the project pom.xml file.
  1. Create a fresh All-in-One (AIO) project to work with. You can use the instructions contained in this tutorial [57] as your guide.
  2. Create a file db_setup_aio.sql with the following contents:

                            
        create database alfrescoaio default character set utf8;
        grant all on alfrescoaio.* to 'alfresco'@'localhost' identified by 'alfresco' with grant option;
        grant all on alfrescoaio.* to 'alfresco'@'localhost.localdomain' identified by 'alfresco' with grant option;                        
                            
                        
    CAUTION:
    Note a different database has been specified here to avoid conflict with the previous tutorial.
  3. Log into your MySQL server as root using the MySQL client:

                            
        mysql -u root -p                        
                            
                        
  4. Run your script to set up the database for Alfresco:

                            
        source db_setup_aio.sql                        
                            
                        

    This will create the Alfresco database and user.

  5. Add a dependency for the MySQL JDBC driver

    Open the {AIO_PROJECT_ROOT}/runner/pom.xml project file. Then add the following dependency at the end of the tomcat7-maven-plugin definition:

                            
    <plugin>
        <groupId>org.apache.tomcat.maven</groupId>
        <artifactId>tomcat7-maven-plugin</artifactId>
    ...
        </configuration>
        <dependencies>
            <dependency>
                <groupId>mysql</groupId>
                <artifactId>mysql-connector-java</artifactId>
                <version>5.1.32</version>
            </dependency>
        </dependencies>
    </plugin>
                        
  6. Now add the configuration required for connecting to your MySQL server

    Open the {AIO_PROJECT_ROOT}/pom.xml project file. Then add the MySQL database connection properties as follows:

             
    <properties>
     ...
        <!-- MySQL configuration -->
        <alfresco.db.name>alfrescoaio</alfresco.db.name>
        <alfresco.db.username>alfresco</alfresco.db.username>
        <alfresco.db.password>alfresco</alfresco.db.password>
        <alfresco.db.host>localhost</alfresco.db.host>
        <alfresco.db.port>3306</alfresco.db.port>
        <alfresco.db.params></alfresco.db.params>
        <alfresco.db.url>jdbc:mysql://${alfresco.db.host}:${alfresco.db.port}/${alfresco.db.name}</alfresco.db.url>
        <alfresco.db.datasource.class>org.gjt.mm.mysql.Driver</alfresco.db.datasource.class>                        
    </properties>
  7. Comment out the H2 Dialect configuration from alfresco-global.properties

    Open the {AIO_PROJECT_ROOT}/repo/src/main/properties/local/alfresco-global.properties configuration file. Then comment out the following line:

                            
    #hibernate.dialect=org.hibernate.dialect.H2Dialect                      
    
    Open the {AIO_PROJECT_ROOT}/repo-amp/src/test/properties/local/alfresco-global.properties configuration file. Then comment out the following line:
                            
    #hibernate.dialect=org.hibernate.dialect.H2Dialect                      
    
  8. Now in the project directory you can type:

                            
        mvn clean install                        
                            
                        
    This step is very important as it cleans up any previous configuration files from target/...
  9. Clean up any previous runs with H2:

                            
        rm -rf alf_data_dev/                        
                            
                        
    This step is also very important as it will remove any content and indexes created when you started with the H2 database. When you switch over to run with MySQL the system thinks that it is the first time that you are running Alfresco, so it will create a new database, new content, and index again, which will clash with any previous starts with H2.
  10. Once you have a successful build the project you can start up Alfresco using:

                            
        mvn install -Prun                        
                            
                        

    Alfresco will start up and use the MySQL database server that you configured. As before, scan the console for messages that confirm that Alfresco has connected to MySQL:

                            
    2014-09-15 16:14:59,912  INFO  [domain.schema.SchemaBootstrap] [localhost-startStop-1] Connecting to database: jdbc:mysql://localhost:3306/alfrescoaio, UserName=alfresco@localhost, MySQL Connector Java
    2014-09-15 16:14:59,913  INFO  [domain.schema.SchemaBootstrap] [localhost-startStop-1] Schema managed by database dialect org.hibernate.dialect.MySQLInnoDBDialect.                        
                            
                        
  11. Point your web browser at http://localhost:8080/share, and log in as admin with password admin.
You have configured the Alfresco SDK to use MySQL rather than H2.
Parent topic: Using MySQL [12]

Source URL: https://docs.alfresco.com/sdk2.1/concepts/alfresco-sdk-intro.html

Links:
[1] http://docs.alfresco.com/
[2] https://github.com/Alfresco/alfresco-sdk/
[3] https://github.com/Alfresco/alfresco-sdk/issues
[4] http://forums.alfresco.com/forum/developer-discussions/development-environment
[5] https://docs.alfresco.com/../concepts/alfresco-sdk-whats-new.html
[6] https://docs.alfresco.com/../concepts/alfresco-sdk-introduction.html
[7] https://docs.alfresco.com/../concepts/alfresco-sdk-getting-started.html
[8] https://docs.alfresco.com/../concepts/alfresco-sdk-cmd-reference.html
[9] https://docs.alfresco.com/../concepts/alfresco-sdk-rad.html
[10] https://docs.alfresco.com/../concepts/alfresco-sdk-advanced-topics.html
[11] https://docs.alfresco.com/../concepts/alfresco-sdk-upgrading.html
[12] https://docs.alfresco.com/../concepts/alfresco-sdk-tutorials-mysql-intro.html
[13] https://wiki.alfresco.com/wiki/Managing_Alfresco_Lifecyle_with_Maven
[14] https://docs.alfresco.com/../concepts/alfresco-sdk-intro.html
[15] https://docs.alfresco.com/../concepts/alfresco-sdk-archetypes.html
[16] https://docs.alfresco.com/../concepts/alfresco-sdk-compatibility.html
[17] https://docs.alfresco.com/../concepts/alfresco-sdk-community-resources.html
[18] https://docs.alfresco.com/../concepts/alfresco-sdk-archetypes-repo-amp.html
[19] https://docs.alfresco.com/../concepts/alfresco-sdk-archetypes-share-amp.html
[20] https://docs.alfresco.com/../concepts/alfresco-sdk-archetypes-aio.html
[21] https://docs.alfresco.com/alfresco-sdk-archetypes-share-amp.html
[22] https://docs.alfresco.com/alfresco-sdk-archetypes-repo-amp.html
[23] https://github.com/Alfresco/alfresco-sdk/issues/180
[24] http://orderofthebee.org/
[25] http://mindthegab.com/
[26] http://www.marversolutions.com/wordpress/2015/01/28/alfresco5-maven-sdk-2/
[27] http://ohej.dk/2014/09/alfresco-sdk-2-0-beta4/
[28] https://docs.alfresco.com/../concepts/alfresco-sdk-before-you-begin.html
[29] https://docs.alfresco.com/../concepts/alfresco-sdk-installing-prerequisite-software.html
[30] https://docs.alfresco.com/../concepts/alfresco-sdk-tutorials-archetypes.html
[31] https://docs.alfresco.com/alfresco-sdk-whats-new.html
[32] https://docs.alfresco.com/alfresco-sdk-compatibility.html
[33] https://docs.alfresco.com/alfresco-sdk-archetypes.html
[34] https://docs.alfresco.com/../tasks/alfresco-sdk-install-spring-loaded.html
[35] https://docs.alfresco.com/../tasks/alfresco-sdk-install-java.html
[36] https://docs.alfresco.com/../tasks/alfresco-sdk-install-java-home.html
[37] https://docs.alfresco.com/../tasks/alfresco-sdk-install-maven.html
[38] https://docs.alfresco.com/../tasks/alfresco-sdk-install-maven-opts.html
[39] https://docs.alfresco.com/../concepts/alfresco-sdk-using-enterprise-edition.html
[40] https://docs.alfresco.com/../tasks/alfresco-sdk-install-verify-install.html
[41] https://github.com/spring-projects/spring-loaded
[42] http://maven.apache.org/download.cgi#Maven_Documentation
[43] http://www.oracle.com/technetwork/java/javase/downloads/index.html
[44] http://docs.oracle.com/javase/8/docs/technotes/guides/install/install_overview.html
[45] http://support.microsoft.com/kb/310519
[46] http://maven.apache.org/download.cgi
[47] http://books.sonatype.com/mvnref-book/reference/installation-sect-maven-install.html
[48] https://artifacts.alfresco.com
[49] https://myalfresco.force.com/support/articles/en_US/Technical_Article/Where-can-I-find-the-repository-for-Enterprise-Maven-artifacts
[50] http://www.alfresco.com/company/contact
[51] https://docs.alfresco.com/../tasks/alfresco-sdk-tutorials-configure-maven-enterprise.html
[52] http://maven.apache.org/guides/mini/guide-encryption.html
[53] https://docs.alfresco.com/alfresco-sdk-archetypes-aio.html
[54] https://docs.alfresco.com/../tasks/alfresco-sdk-tutorials-amp-archetype.html
[55] https://docs.alfresco.com/../tasks/alfresco-sdk-tutorials-share-amp-archetype.html
[56] https://docs.alfresco.com/../tasks/alfresco-sdk-tutorials-all-in-one-archetype.html
[57] https://docs.alfresco.com/alfresco-sdk-tutorials-all-in-one-archetype.html
[58] https://docs.alfresco.com/alfresco-sdk-tutorials-amp-archetype.html
[59] https://docs.alfresco.com/../concepts/alfresco-sdk-cmd-reference-repo-amp.html
[60] https://docs.alfresco.com/../concepts/alfresco-sdk-cmd-reference-share-amp.html
[61] https://docs.alfresco.com/../concepts/alfresco-sdk-cmd-reference-aio.html
[62] https://docs.alfresco.com/../tasks/alfresco-sdk-rad-eclipse-import-projects.html
[63] https://docs.alfresco.com/../tasks/alfresco-sdk-rad-eclipse-hot-reloading.html
[64] https://docs.alfresco.com/../tasks/alfresco-sdk-rad-intellij-import-projects.html
[65] https://docs.alfresco.com/../tasks/alfresco-sdk-rad-intellij-hot-reloading.html
[66] https://docs.alfresco.com/../tasks/alfresco-sdk-rad-eclipse-remote-debugging.html
[67] https://docs.alfresco.com/alfresco-sdk-rad-eclipse-import-projects.html
[68] https://docs.alfresco.com/alfresco-sdk-rad-intellij-import-projects.html
[69] https://docs.alfresco.com/../concepts/alfresco-sdk-advanced-add-custom-amps.html
[70] https://docs.alfresco.com/../tasks/alfresco-sdk-advanced-configure-ssl-repo-solr.html
[71] https://docs.alfresco.com/../tasks/alfresco-sdk-advanced-adding-internal-external-jars-to-repo-amp.html
[72] https://docs.alfresco.com/../tasks/alfresco-sdk-advanced-link-alf-amps-aio.html
[73] https://nilhcem.github.io/FakeSMTP/
[74] https://docs.alfresco.com/../tasks/alfresco-sdk-advanced-link-custom-amps-aio.html
[75] https://docs.alfresco.com/../tasks/alfresco-sdk-advanced-add-custom-amps-aio.html
[76] https://docs.alfresco.com/alfresco-sdk-tutorials-share-amp-archetype.html
[77] https://docs.alfresco.com/../tasks/alfresco-sdk-upgrading-alfresco-version.html
[78] https://docs.alfresco.com/../concepts/alfresco-sdk-upgrading-sdk-version.html
[79] https://docs.alfresco.com/../concepts/alfresco-sdk-upgrading-what-changes-are-allowed-in-release.html
[80] https://docs.alfresco.com/../concepts/alfresco-sdk-upgrading-sdkversion-200-210.html
[81] https://docs.alfresco.com/../tasks/alfresco-sdk-upgrading-repo-amp-sdkversion-200-210.html
[82] https://docs.alfresco.com/../tasks/alfresco-sdk-upgrading-share-amp-sdkversion-200-210.html
[83] https://docs.alfresco.com/../tasks/alfresco-sdk-upgrading-aio-sdkversion-200-210.html
[84] https://docs.alfresco.com/alfresco-sdk-advanced-add-custom-amps-aio.html
[85] http://www.mysql.com
[86] https://docs.alfresco.com/../tasks/alfresco-sdk-tutorials-using-mysql-simple-amp.html
[87] https://docs.alfresco.com/../tasks/alfresco-sdk-tutorials-using-mysql-all-in-one.html
[88] http://dev.mysql.com/doc/