Thursday, March 12, 2015

Getting Started with Maven Alfresco SDK 2.0


As we know old Ant based SDK has been replaced with Maven based SDK in Alfresco 5.0.x.
Here, we will see How to get started with Alfresco development using Alfresco Maven SDK.

Need to follow below steps to create Maven based project. Here we will use Enterprise artifacts.

I am assuming you already have JDK 1.7 and Maven 3.2.5 installed.
  1. You need to have enterprise credential to access Alfresco Private Repository. Enterprise artifacts are stored in Alfresco Private Repository and it can be accessed only by Enterprise users.

  2. Edit settings.xml under your .m2 directory. .m2 folder is generally located at C:\Users\<UserName>\.m2 in windows. Add following server configurations under <servers>

  3.                     <server>
                                    <id>alfresco-private-repository</id>
                                    <username>TestUser</username>
                                    <password>MyPwd</password>
                        </server>

  4. Create a directory where you want to create new maven based project

  5. You can create three types of Project based on archtypes. For details of this archtypes please check- http://docs.alfresco.com/5.0/concepts/alfresco-sdk-usage.html

  6.                     a. Alfresco AMP archetype
                        b. Alfresco Share AMP archetype
                        c. Alfresco all-in-one archtype (AIO)

  7. Switch to new directory and run following command

  8.                  mvn archetype:generate -Dfilter=org.alfresco.maven.archetype:

  9. Next you need to choose archtype. Here I would select alfresco-amp-archetype

  10. Next to choose an archetype version. I would select 2.0.0

  11. Then, You will be prompted to enter a value of groupId. Its like package name. You can enter any. I will enter com.alfresco.test

  12. Then you will be asked to define artifactId. It can be like your project name. I will enter test-repo-project

  13. Next, You will be prompted to enter a value for the Alfresco version you wish to develop against - currently the default is 5.0.c. Hit the Enter key to accept the default value. Later we will change it.

  14. You will get log as below and your new project test-repo-project is created with required folders and configuration files.

  15. To understand project structure please check - http://docs.alfresco.com/5.0/concepts/alfresco-sdk-project-structure.html

  16. [INFO] ----------------------------------------------------------------------------
    [INFO] Using following parameters for creating project from Archetype: alfresco-amp-archetype:2.0.0
    [INFO] ----------------------------------------------------------------------------
    [INFO] Parameter: groupId, Value: com.alfresco.test
    [INFO] Parameter: artifactId, Value: test-repo-project
    [INFO] Parameter: version, Value: 1.0-SNAPSHOT
    [INFO] Parameter: package, Value: (not used)
    [INFO] Parameter: packageInPathFormat, Value: (not used)
    [INFO] Parameter: package, Value: (not used)
    [INFO] Parameter: version, Value: 1.0-SNAPSHOT
    [INFO] Parameter: groupId, Value: com.alfresco.test
    [INFO] Parameter: alfresco_target_version, Value: 5.0.c
    [INFO] Parameter: artifactId, Value: test-repo-project
    [INFO] Parameter: alfresco_target_groupId, Value: org.alfresco
    [INFO] project created from Archetype in dir: D:\alfrescoMVNWorkspace\test-repo-project
    [INFO] ------------------------------------------------------------------------
    [INFO] BUILD SUCCESS
    [INFO] ------------------------------------------------------------------------
    [INFO] Total time: 06:28 min
    [INFO] Finished at: 2015-03-12T15:39:22+05:30
    [INFO] Final Memory: 16M/121M
    [INFO] ------------------------------------------------------------------------

  17. Once project is created you can start your development. Before that you can build and verify your project.

  18. We want to use enterprise artifact so we need to modify pom.xml of test-repo-project

  19. Go to test-repo-project and edit pom.xml and change the values of alfresco.groupId and alfresco.version to specify Enterprise artifacts.
    Please check this http://docs.alfresco.com/5.0/concepts/alfresco-sdk-tutorials-alfresco-enterprise.html to select correct value of both properties. Here I will set it as below.

  20. <alfresco.groupId>org.alfresco</alfresco.groupId>
    <alfresco.version>5.0.0</alfresco.version>

  21. Go to cmd and change your current directory to - test-repo-project and type following command. It will download enterprise artifact to build your project and it will also run the project. For first time it may take time to build as it’s downloading all required dependencies.

  22.                  mvn install -Prun,enterprise

  23. Once build is successful login to Share and verify if you have any custom changes.
ISSUE: You might face this unauthorized error message issue while downloading enterprise artifact. To solve it add <server> configuration in your settings.xml as below
        <server>
                <id>alfresco-internal</id>
                <username>TestUser</username>
                <password>MyPwd</password>
        </server>

Other useful commands:

To build project:
          mvn package
Install amp in your local repo:
          mvn install
By default, build includes to run test, If you want to skip test cases
    mvn install -DskipTests=true
To delete all compiles artifacts
        mvn clean

No comments:

Post a Comment