[HOWTO] Build your JAR Alfresco Share Dashlet with Maven in 3 minutes

written by MindTheGab on February 23, 2010 in alfresco and application lifecycle management and howto and maven and opensource and share with 4 comments
Follow me!

MindTheGab

WW Manager, Expert Services at Alfresco Software
Grown in the flourishing Open Source Enterprise ecosystem of the last decade, bringing a wealth of expertise on ECM and Application Lifecycle Management, both in terms of Product and People leadership.

With a masters thesis on Business Process Re-engineering on a fully open source stack and 10 years in the tech business between Services, Sales and Engineering, he developed a full-spectrum technical and business expertise, in the context of large scale Enterprise Content Management projects for key government and Fortune 500 global customers.
Follow me!

Two months without a post, and I come back again with Maven and Alfresco? Well, no news as the Maven Alfresco Community keeps growing..

So following the exciting news on Spring Surf and Share announced by Kev on trunk, for which since Alfresco 3.3 (now in trunk) we can now build Alfresco Share Extensions as plain old JARs, I decided to complete the Maven Alfresco Lifecycle with another archetype, providing a simple way and sample code allowing to build Maven2 Alfresco Share Extensions in minutes.

I’m sure this is going to interest the Alfresco community, same as it’s Ant counterpart build script which Will’s recently produced to accomplish the same task. The more, the merrier isn’t it? The big difference between that approach and the one we’re presenting is only that Maven enforce a standard project layout so it was fairly easy to put stuff to be packaged in the proper place.

This also comes as a very natural complement to the Maven Alfresco Share Extension Archetype (managing WAR customized builds for Share) for now it’s possible to build a Share WAR and have it depend on Share JAR modules. Great kudos go to colleague and mate Will Abson and Alfresco Engineers for having produced and nurtured the Site Tags Dashlet which is included in this archetype and that you can install following the next steps in a couple of minutes.

Couple of pre-requisites for running this:

  • Alfresco Repository WAR 3.3 (TRUNK) already running on Tomcat. You can build this from trunk and run it in your tomcat instance, or find it deployed in the Maven Alfresco Community Repository
  • Tomcat Manager already installed and using credentials “admin” with no password (config in conf/tomcat-users.xml)
  •  (optionally) m2Eclipse eclipse plugin to import Maven project (not needed but cool :) )

Ready, set, go:

  1.  Create a Share Extension WAR using the Maven Alfresco Share Extension Archetype:
    • mvn archetype:generate -DarchetypeGroupId=org.alfresco.maven -DarchetypeArtifactId=maven-alfresco-share-archetype -DarchetypeVersion=1.9.2-SNAPSHOT -DgroupId=com.mycompany -DartifactId=my-custom-share -Dversion=1.0-SNAPSHOT -DarchetypeRepository=http://maven.alfresco.com/nexus/content/repositories/snapshots -DinteractiveMode=false
    • A project folder called my-custom-share  gets created, with packaging WAR
  2. Modify which Alfresco Share version you’re using, by changing the alfresco.version property in pom.xml to be 3.3-SNAPSHOT (JAR modules will just work on Alfresco 3.3+ instances)
  3. (Optionally) Test packaging and deployment of vanilla Alfresco Share 3.3 on the running Tomcat by
  4. Proceed with creation of sample module, by creating base JAR module project structure using the Maven Alfresco Share Module Archetype
    • mvn archetype:generate -DarchetypeGroupId=org.alfresco.maven -DarchetypeArtifactId=maven-alfresco-share-module-archetype -DarchetypeVersion=1.0.0-SNAPSHOT -DgroupId=com.mycompany -DartifactId=my-custom-share-module -Dversion=1.0-SNAPSHOT -DarchetypeRepository=http://maven.alfresco.com/nexus/content/repositories/snapshots -DinteractiveMode=false
    • A project folder called my-custom-share-module  gets created, with packaging JAR
    • This project folder contains a Maven project which ships the Site Tags Dashlet
  5.   Install your module into local maven repo (or remote one if you have on)
    • cd my-custom-share-module
      mvn install
  6. Include the Share module in your Share build, by just creating a Share WAR –> Share Module JAR dependency in perfect Maven style
    • Add the following snippet to the my-custom-share/pom.xml file:

      <!-- Share module dependencies -->
      <dependency>
      <groupId>com.mycompany</groupId>
      <artifactId>my-custom-share-module</artifactId>
      <type>jar</type>
      <version>1.0-SNAPSHOT</version>
      </dependency>

  7. Redeploy your Share WAR to Tomcat with the newly added dependency by:
    • cd my-custom-share
      mvn clean tomcat:redeploy

    Alfresco Share Site Tags Dashlet

  8. If all went right, you should be able to
    • point your browser to http://localhost:8080/my-custom-share
    • Create a test site
    • Log into your site and go to “Customize Dashboard
    • Clicking on the “Add Dashlets” should show you the availability of a new dashlet called Tag Cloud. There we are! :)
    • Once added the Dashlet to the site you should be able to see something like the attached screenshot

Easy wasn’t it? :)

Now starting from the site dashlet you a a Maven powered, fully enterprise scalable (easy to manage multiple and complex development cycles) and IDE independent SDK for developing Share extensions. Also this integrates quite neatly with your Eclipse/Netbeans standard environments. Specifically for Eclipse,  using m2Eclipse “Import” –> “Maven Projects”  feature and point to the folders of just created project will easily import both WAR and JAR projects in your standard environment (see screenshot) . You can also invoke Maven from Eclipse, and bye bye to the command line :)

Eclipse Imported Project

Eager to hear your thoughts and contributions if you like this approach :)

About Gabriele Columbro

Grown in the flourishing Open Source Enterprise ecosystem of the last decade, bringing a wealth of expertise on ECM and Application Lifecycle Management, both in terms of Product and People leadership. With a masters thesis on Business Process Re-engineering on a fully open source stack and 10 years in the tech business between Services, Sales and Engineering, he developed a full-spectrum technical and business expertise, in the context of large scale Enterprise Content Management projects for key government and Fortune 500 global customers.