Saturday, June 21, 2014

Amp-Archetype from Maven Alfresco SDK goodness

I'm now a fan of the AMP Archetype from Maven Alfresco SDK (version 1.1.1). In this blog I will explain how I got to using this maven archetype toolkit and the tweaks I made to the template output to fit my local development needs.

A little bit of history...
Local development prior to using the Amp Archetype had been the following below list.  It's worked out well, and I find it very stable.  I'll go back to doing it this way if I find any limitations in the embedded tomcat/H2 DB/lucene version.
  1. Download the windows .exe or linux .bin self extracting/installing files  
  2. Configure non-postgresql DB for use if necessary with alfresco-global.properties in the shared classes location
  3. Configure a custom-log4j.properties in the shared classes extension location
  4. Both alfresco and share wars installed on the same container
  5. Make .bat/.sh script to install amp into war and deploy to target container location
  6. Make .bat/.sh script to recursively copy from the source code amp location to the installed war location for files that don't require a container restart
  7. Enable Jrebel support for any Java changes (view my previous post on that)
I spent some time working with the All-in-One-Archetype also - my initial thoughts were:
  1. Good to get most developers up and running
  2. Good you can change the alfresco version on the fly in the pom
  3. Bad because: 
    • SLOW to start up (9 mins on my machine)
    • Can't control tomcat to the extent of if you deployed manually (Not all bin or conf files were available)
    • Doesn't match what the target environment would use
    • Comes with a default alfresco-global.properties which is completely different than the standard alfresco install sample file.
    • Both alfresco and share are included, if you don't need share, then you don't need share
    • The log4j.properties was contained in the amp when built
      • Yes we can have multiple log4j.properties in the classpath, and yes there are classpath loading orders, but I've always found it clearer to just use a custom-log4j.properties in the shared classes alfresco extension folder to override any OOB alfresco WEB-INF/classes/log4j.properties file
Tweaking the maven template output after creating the Amp-Archetype
I decided to try the Amp-Archetype to see if I would like it better.  I am a real fan now.   It's much faster to start the embedded containers, and it's a good idea to separate out alfresco and share in it's own containers, since you only need to start alfresco if you need to work on it that day. This article helped immensely to set it up.  

Here's how I tweaked the template output after creating the archetype:
  1. One amp-archetype for alfresco and a separate one for share
    • Improvement: the Amp Archetype should be split in an Amp-Repo-Archetype and a Amp-Share-Archetype possibly since the files needed would be slightly different.
  2. Alfresco
    • Added additional properties to the OOB src/test/resources/alfresco-global.properties to recognize what share is running, since share is running on a different port
    • Deleted:
      • All log4j.properties files.  I am using custom-log4j.properties instead
        • src/main/amp/config/alfresco/module/<artifact id>/log4j.properties
        • src/main/amp/log4j.properties
        • src/test/resources/log4j.properties
      • All the Demo components.  Nice to have for newbies to alfresco, but I didn't need it. Plus the build was running an integration test which makes it slow
    • Added:
      • src/test/resources/alfresco/extension/custom-log4j.properties
    • Takes approximately two minutes to start up if I include the maven clean build phase
  3. Share
    • Note: Kept the src/test/resources/log4j.properties file.  
      • Had to copy over the share OOB log4j.properties into it, then add my customizations on top
      • Could also use same strategy for custom-log4j.properties as alfresco here
    • Deleted:
      • src/test/properties/local/alfresco-global.properties.  This is only for the Alfresco repository, not needed for share
      • src/main/amp/config/alfresco/module/<artifact id>/log4j.properties
      • src/main/amp/log4j.properties
      • All the Demo components.  Demo components are for Alfresco repo, not share
    • Takes approximately two minutes to start up if I include the maven clean build phase
  4. For both alfresco and share:
    • In the root maven module folder:
      • Created a .bat/.sh file to start alfresco/share.  It defines the DEBUG_OPTS, MAVEN_OPTS, JAVA_HOME, MAVEN_HOME, and a flag to start with JRebel or non-JRebel support (reference this article and this article)
      • Created a .bat/.sh file to recursively copy from the amp location to the installed war location for files that don't require a container restart
      • runAlfresco.bat
        • rem Instructions for starting local Alfresco Repository
          rem Make sure to change the following:
          rem 1.  Folder to your alfresco explorer maven alfresco sdk
          rem 2.  Debug port can be used on your workstation.  NOTE: the debug option shouldn't be turned on on a production server
          rem 3.  Java Home
          rem 4.  Maven Home
          rem 5.  You can change the port this runs on if necessary: -Dmaven.tomcat.port=8081
          rem 6.  If running with rad and jrebel, the JREBEL_OPTS 
          
          set DEBUG_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,address=1044,server=y,suspend=n
          set MAVEN_OPTS=%DEBUG_OPTS% -Xms1024m -Xmx4096m -XX:PermSize=1024m
          set JAVA_HOME=C:\Apps\Java\jdk1.7.0_67
          set MAVEN_HOME=C:\Apps\apache-maven-3.2.2
          mvn clean integration-test -Pamp-to-war
          
          rem If you have a jrebel license then: comment out the above mvn line, and uncomment out the below 3 lines to run with jrebel
          rem set JREBEL_OPTS=-javaagent:C:\Apps\jrebel\jrebel.jar -noverify
          rem set MAVEN_OPTS=%MAVEN_OPTS% %JREBEL_OPTS%
          rem mvn clean integration-test -Pamp-to-war,rad
          
      • runShare.bat
        • rem Instructions for starting local Share
          rem Make sure to change the following:
          rem 1.  Folder to your alfresco share maven alfresco sdk
          rem 2.  Debug port can be used on your workstation.  NOTE: the debug option shouldn't be turned on on a production server
          rem 3.  Java Home
          rem 4.  Maven Home
          rem 5.  You can change the port this runs on if necessary: -Dmaven.tomcat.port=8081 (then you also have to change alfresco module alfresco-global.properties)
          rem 6.  If running with rad and jrebel, the JREBEL_OPTS 
          
          set DEBUG_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,address=1045,server=y,suspend=n
          set MAVEN_OPTS=%DEBUG_OPTS% -Xms1024m -Xmx4096m -XX:PermSize=1024m
          set JAVA_HOME=C:\Apps\Java\jdk1.7.0_67
          set MAVEN_HOME=C:\Apps\apache-maven-3.2.2
          mvn clean integration-test -Pamp-to-war -Dmaven.tomcat.port=8081
          
          rem If you have a jrebel license then: comment out the above mvn line, and uncomment out the below 3 lines to run with jrebel
          rem set JREBEL_OPTS=-javaagent:C:\Apps\jrebel\jrebel.jar -noverify
          rem set MAVEN_OPTS=%MAVEN_OPTS% %JREBEL_OPTS%
          rem mvn clean integration-test -Pamp-to-war,rad -Dmaven.tomcat.port=8081
          
For more examples and ideas, I encourage you explore the links provided throughout this blog. What questions do you have about this post? Let me know in the comments section below, and I will answer each one.

NOTE, to make this work with alfresco enterprise version, do the following:
  • Add alfresco nexus private repo server info to .m2 settings.xml file
    <!-- Needed for alfresco private repo -->
    <server>
        <id>alfresco-artifacts-repository</id>
        <username>yourusername</username>
        <password>yourpassword</password>
    </server>
    
POM changes
  • Add private alfresco nexus repository to pom.  Note the private repository name must match the server id you added in settings.xml in the previous step.
    <repositories>
        <!-- add private repo for enterprise -->
        <repository>
            <id>alfresco-artifacts-repository</id>
            <url>https://artifacts.alfresco.com/nexus/content/groups/private</url>
        </repository>
        <repository>
            <id>alfresco-artifacts</id>
            <url>https://artifacts.alfresco.com/nexus/content/groups/public</url>
        </repository>
        <repository>
            <id>alfresco-artifacts-snapshots</id>
            <url>https://artifacts.alfresco.com/nexus/content/groups/public-snapshots</url>
        </repository>
    </repositories>
    
  • You may have to change the alfresco.groupId and alfresco.client.war.groupId values, depending on the alfresco enterprise version you are using (i.e. 4.1.x is in org.alfresco.enterprise, but 4.2.x is in org.enterprise!).  
    • In properties, change the group id to enterprise for both (instead of org.alfresco, use org.alfresco.enterprise).  
      <alfresco.groupId>org.alfresco.enterprise</alfresco.groupId>
      <alfresco.client.war.groupId>org.alfresco.enterprise</alfresco.client.war.groupId>
      


3 comments:

  1. I'm sorry for commenting the old post. However, I'd like to leave this message here for people like me, who will find this post while trying to debug slow Alfresco startup when using Alfresco Maven SDK.

    I experienced exactly this issue today, and 9 minutes to start is definitely not normal for Alfresco. There is a chance, that you are hit by network misconfiguration, as described here - http://blog.itdhq.com/post/133135613685/alfresco-sdk-fixing-mysteriously-slow-tomcat

    ReplyDelete
    Replies
    1. Thanks for your comment.

      I'm curious, did you see the slowness (and java.net.Inet6AddressImpl.lookupAllHostAddr() code) using the all in one archetype or the amp archetype? I only saw the slowness using the all in one archetype.

      Delete
  2. This comment has been removed by the author.

    ReplyDelete

I appreciate your time in leaving a comment!