This week’s How-to will explain you how to get started with Alfresco SDK using Maven.
From Alfresco 5.0.X version Alfresco has been moved to Maven based SDK from Ant Based SDK, here I want to give you how to start with Alfresco SDK using Maven.
Pre requisites for Alfresco Maven SDK:
JDK 1.7 and Maven 3.2.5 installed
Credential to access Alfresco Private Repository. Enterprise artifacts are stored in Alfresco Private Repository and it can be accessed only by Enterprise users, please refer to this knowledge base article.
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.
- Edit settings.xml to add your private server credentials those you obtained from Alfresco. As below:
<server> <id>alfresco-artifacts-repository </id> <username>username</username> <password>password</password> </server>
- Create a directory where you want to create new maven based project
- From command prompt open the above created directory and type the following command:
mvn archetype:generate -Dfilter=org.alfresco.maven.archetype:
Â
- Next you need to choose archtype. Here Select the All-in-One
- Select the default archetype version number.
- Then, You will be prompted to enter a value of groupId. Its like package name. You can enter any. Then you will be asked to define artifactId. It can be like your project name.
- Next, You will be prompted to enter a value for the Alfresco version you wish to develop against – currently the default is 5.0.0 . Hit the Enter key to accept the default value. Later we will change it.
You will get some logs and your new project is created with required folders and configuration files
- Now go to the project directory and add alfresco enterprise repository to pom.xml file
<repositories> <repository> <id>alfresco-artifacts-repository</id> <url>http://artifacts.alfresco.com/nexus/content/groups/private/</url> </repository> </repositories>
- Now we are set to build the project, open project folder on command prompt and type the below command
mvn install -Prun,enterprise
This will build the project, downloading Enterprise artifacts from the Alfresco private repository as required, and run the project.
Once the application is running you can point your web browser at http://localhost:8080/share.
You might need to wait some time before Alfresco has fully started. Look for the message: INFO: Starting ProtocolHandler [“http-bio-8080”], which indicates the server has started.
Â
Below are some 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