Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

CQCON CQ Maven Methods


Published on

This talk was presented at CQCON 2013 in Basel.

Learn how to master development workflows combining the power of CQ with Apache Maven and Git. Sometimes it can be hard to get up and running with other developers' Adobe CQ projects. Where is the code? How can you build it once you have it? How do you get it into CQ? What do you do with it once it's there? Anyone should be able to quickly and easily perform a git clone of a CQ project, followed by doing a Maven build and install, and then immediately be able to try it out and work on it within CQ. This session will show developers how they can structure their projects so that they are buildable "out of the box". We will provide hints and tips on how to structure your application in git, and explain which maven plugins to use in a range of circumstances.

See the CQCON website or the online version of the presentation at
The source of the presentation is in github at

Published in: Technology
  • Be the first to comment

  • Be the first to like this

CQCON CQ Maven Methods

  3. 3. Joined Adobe in November 2012
  4. 4. CQ NewbieJCR/CMS/TLA old hat
  5. 5. Background in Open Source, Content Management, Mobile
  6. 6. Talking today about what I learned so far...
  7. 7. FORK ME!If you found this talk useful, or spotted
  9. 9. SEE ALSO
  10. 10. LETS BUILD A CQ SITE... uh, where to begin?
  11. 11. METHOD 1Enthusiastically rush in, use CRXDE Lite
  12. 12. METHOD 2Im a guru, I use Eclipse and CRXDE
  13. 13. METHOD 3Im a ninja, I use emacs and vlt
  14. 14. METHOD 4Im a guru ninja, I use vi and curl
  15. 15. METHOD 5See also: – Real Programmers
  16. 16. BUT WHAT ABOUT ...reverting mistakes?reproducible builds?collaborating with others?deploying to production?
  17. 17. WHY ISNT IT EASIER TO BUILD A CQ SITE?Laborious project inceptionNo two projects alikeDont know project layoutDont know project dependenciesHard for others to reproduceHard to testLengthy RTFM or worse (no FM)Documentation over convention
  18. 18. CQ SUCKS
  19. 19. $PRODUCT SUCKS
  21. 21. SO HOW DO WE FIX THIS?MavenGit(or Subversion, or CVS ... ymmv)Best Practices
  22. 22. MAVEN“Maven is a software project managementand comprehension tool. Based on theconcept of a project object model (POM),Maven can manage a projects build,reporting and documentation from a centralpiece of information.”
  23. 23. GIT“Git is a free and open source distributedversion control system designed to handleeverything from small to very large projectswith speed and efficiency. ”Version control is a system that records changes to a file or set of files overtime so that you can recall specific versions later.
  24. 24. BEST PRACTICES“A best practice is a method or technique thathas consistently shown results superior tothose achieved with other means.”In addition, a "best" practice can evolve to become better as improvementsare discovered.
  25. 25. WHAT DO WE WANT?Minimal customisationStandardised way to create a projectStandardised way to build a projectStandardised way to deploy a projectStandardised way to test a projectStandardised way to share a project
  26. 26. OUR TARGET
  27. 27. Success criteria:ITS EASY TO BUILD A CQ SITE!
  28. 28. GETTING STARTEDInstall Maven: Git:
  29. 29. CONFIGURING MAVENMaven has a settings file that defines things likerepositories where plugins can be downloaded (typically~/.m2/settings.xml).We need to add a profile to point to the Adobe repository.We then specify this repository when we use thearchetype plugin.See also: Obtaining the Content Package Maven Plugin
  30. 30. CONFIGURING MAVEN<profile><id>adobe-public</id><activation><activeByDefault>false</activeByDefault></activation><properties><releaseRepository-Id>adobe-public-releases</releaseRepository-Id><releaseRepository-Name>Adobe Public Releases</releaseRepository-Name><releaseRepository-URL></releaseRepository-URL></properties><repositories><repository><id>adobe-public-releases</id><name>Adobe Basel Public Repository</name><url></url><releases><enabled>true</enabled><updatePolicy>never</updatePolicy></releases><snapshots><enabled>false</enabled></snapshots></repository></repositories><pluginRepositories><pluginRepository><id>adobe-public-releases</id><name>Adobe Basel Public Repository</name><url></url><releases><enabled>true</enabled><updatePolicy>never</updatePolicy></releases><snapshots><enabled>false</enabled></snapshots></pluginRepository></pluginRepositories></profile>
  31. 31. CONFIGURING MAVENEnable the repository:Or use the -P option to activate profile(s):<activeProfiles><activeProfile>adobe-public</activeProfile></activeProfiles>mvn -P adobe-public [...]
  32. 32. USING MAVEN
  33. 33. STARTING A NEW PROJECT ...... can sometimes feel like reinventing the wheel.
  34. 34. YOU ARE HERE
  35. 35. ARCHETYPESarchetype |ˈɑːkɪtʌɪp|nouna very typical example of a certain person or thing: he wasthe archetype of the old-style football club original which has been imitated; a prototype: aninstrument which was the archetype of the early flute.
  36. 36. MAVEN ARCHETYPESA prototype upon which others arecopied, patterned, or emulated.
  37. 37. WHAT CQ ARCHETYPES ARE THERE?simple-content-packageGenerates a simplemultimodule-content-packageIncludes the folder structure for developing a CQapplication (content package and bundle).cqblueprints multi-moduleThird-party archetype encapsulating best practices forworking with e.g. OSGi bundles, taglibs, and CQ contentSee also:content packageHow to work with packages
  38. 38. ON PACKAGESPackages enable the importing and exporting of repositorycontent. They are used to install new functionality, transfercontent between instances, or back up the repositoryA package is a zip file in file system (vault) serializationformatPackages include meta information - filter definitions,import configuration, package propertiesPackages are often managed through the CQPackage Manager
  39. 39. ON BUNDLESBundles are modular containers of functionality for OSGi –essentially a java module that contains application logicBundles consist of java classes and other resources neededto deliver functionality or to provide services to otherbundles.Bundles can be managed through the CQSee also:Web ConsoleCreating OSGi bundles using CRXDE
  40. 40. HOW TO USE AN ARCHETYPEarchetypeGroupId: identifies the archetype projectuniquely across all projectsarchetypeArtifactId: the name of the archetype jarwithout a version numberarchetypeRepository: where to get the archetype from(based on pluginRepository in settings.xml)See also: andmvn archetype:generate-DarchetypeGroupId=foo-DarchetypeArtifactId=bar-DarchetypeVersion=1.0.0-DarchetypeRepository=bazMaven: Introduction to Archetypes Maven: Naming conventions
  41. 41. SIMPLE CONTENT PACKAGE ARCHETYPEFrom the fine manual:“Creates a maven project that is suitable forinstalling resources for a simple CQapplication. The folder structure is that usedbelow the /apps folder of the CQ repository.The POM defines commands for packagingthe resources that you place in the folders andinstalling the packages on the CQ server.”
  42. 42. SIMPLE CONTENT PACKAGE USAGEarchetypeGroupId: the archetype project uniquely across all projectsarchetypeArtifactId: simple-content-package-archetypethe name of the archetype jar without a version numberarchetypeRepository: adobe-public-releaseswhere to get the archetype from (based onpluginRepository in settings.xml)mvn
  44. 44. SIMPLE CONTENT PACKAGE PARAMETERSgroupId: Like a package name, name of the jar without the version, e.g.myprojectversion: accept the defaultpackage: not used in simple-content-packageappsFolderName: name of /apps/myproject, e.g. myprojectartifactName: Description in Package ManagerpackageGroup: Group in Package ManagerSee also: Maven: Naming conventions
  45. 45. SIMPLE CONTENT PACKAGE OUTPUTTemplate directoriespom.xml fileInstructions for compiling, creating bundles, deployingto CQ in packagesFileVault configuration files
  47. 47. MULTIMODULE CONTENT PACKAGE OUTPUT${artifactId}|- pom.xml|- bundle|- pom.xml|- src|- main|- java|- ${groupId}|-|- test|- java|- ${groupId}|-|- content|- pom.xml|- src|- main|- content|- jcr_root|- apps|- ${appsFolderName}|- config|- install|- META-INF|- vault|- config.xml
  48. 48. |- filter.xml|- nodetypes.cnd|- properties.xml|- definition|- .content.xml
  49. 49. CQBLUEPRINTS MULTI-MODULE USAGEFirst add the CQ Blueprints Maven Repository to Mavenssettings.xml, then:archetypeGroupID: com.cqblueprints.archetypesarchetypeArtifactId: multi-modulearchetypeVersion: 1.0.5archetypeRepository: cqblueprints.plugins.releasesSee also: andmvn -P cqblueprints archetype:generate-DarchetypeGroupId=com.cqblueprints.archetypes-DarchetypeArtifactId=multi-module-DarchetypeVersion=1.0.5-DarchetypeRepository=cqblueprints.plugins.releasesConnecting to the CQ Blueprints Repository The CQ Project Maven Archetype
  50. 50. CQBLUEPRINTS MULTI-MODULE OUTPUT${artifactId}|- README|- pom.xml|- ${artifactId}-all|- pom.xml|- ${artifactId}-config|- ${artifactId}-content|- ${artifactId}-services|- ${artifactId}-taglib|- ${artifactId}-view
  51. 51. WHY USE CQBLUEPRINTS MULTI-MODULE?The cqblueprint multi-module archetype is developed by“The things we wanted to consider with ourarchetype is to address concerns of largerteams”
  52. 52. CQBLUEPRINTS MULTIMODULE DESIGNfoo-view subproject: where css/html/js developers (frontend)do their workfoo-taglib foo-services: where java developers (backend) dotheir workfoo-config: where the configuration (runmode configs stored)foo-content: how we get initial content and site structure ontothe developers box quicklyfoo-all: how we hand off builds to the next environment
  53. 53. USING GIT
  54. 54. WHY GIT?Local safety net"The internet is my backup"Its good to shareEnlightened self-interest
  55. 55. YOU ARE HERE
  56. 56. GIT PROJECT SETUPcd projectnamegit init
  57. 57. GIT IGNOREEdit .gitignore, for example:.classpath.project.vlt/.settings/target/
  58. 58. GET IT IN GITgit add *git commit -m Initial project version
  59. 59. GET IT IN GITHUB (OPTIONAL)hub-new-repo is a shortcut for creating a repository ongithub and pushing your local repo into itSee also:See also:cd projectgit hub-new-repoCLI remote github repo creationgithub
  60. 60. DEMO
  61. 61. ... TIME PASSES ...
  62. 62. COMMIT PROJECTgit add filenamesgit commit -m "meaningful message"git push origin master
  63. 63. (BEST) PRACTICE(S)
  64. 64. YOU ARE HERE
  65. 65. “the three great virtues of a programmer:laziness, impatience, and hubris”
  66. 66. BUILDING
  67. 67. HOW CAN WE BUILD SMARTER?Create local zips and jars that you can upload:mvn packageproduces:Content package output: target/yourapp-content-1.0-SNAPSHOT.zipBundle output: target/testapp-bundle-1.0-SNAPSHOT.jar
  68. 68. DEPLOYING
  69. 69. HOW CAN WE BUILD AND DEPLOY SMARTER?Content package: mvn -PautoInstallPackageinstallBundle: mvn -PautoInstallBundle installcqblueprints: mvn -Pauto-deploy install
  70. 70. DEMO
  71. 71. DEVELOPING
  72. 72. YOU ARE HERE
  73. 73. How do we develop in a world of maven builds and deploysand git saves?
  74. 74. THE FILEVAULT TOOLYou can use the FileVault tool (vlt) to check in, check out,update and sync local content with the repository.Install: extract crx-quickstart/opt/filevault/filevault.[tgz|zip] and add to your pathUsage: vlt --credentials admin:admin co --force http://localhost:4502/crxSee also: How to use the VLT Tool
  75. 75. SAMPLE DEVELOPMENT WORKFLOWUse maven to build and deployInitialise vltCreate components, templates with CRXDE LiteUse vlt to copy back into local filesystemChange locallyUse vlt to copy back into the repositoryAdd to git
  76. 76. DEMO
  77. 77. TESTING
  78. 78. CONTINUOUS INTEGRATION?with ,as awith andJenkins Git plugin GitHub pluginSelenium serverCucumber for java Jenkins plugin tests in java
  79. 79. INTEGRATION TESTING FRAMEWORK... see Lydias talk
  80. 80. PRODUCTION
  81. 81. How do we move to production in a world of maven builds anddeploys and git saves?
  82. 82. YOU ARE HERE
  83. 83. MAVEN PROFILE FOR PRODUCTIONAdd this to pom.xml:Deploy using this profile:Or one-time override: mvn,crx.port=4504 -PautoInstallPackage installSee also:<profile><id>auto-deploy-prod</id><properties><>production.server.hostname</><crx.port>4502</crx.port></properties></profile>mvn -PautoInstallPackage,auto-deploy-prod installIntroduction to build profiles
  84. 84. DEPLOYMENT TESTING... see Bertrands talk
  86. 86. 0-60 IN 5 PSEUDO LINESmvn archetype:generategit init; git add *; git commit -m "Initial project"mvn -PautoInstallPackage installvlt checkout ; vlt update ; vlt commitgit add; git commit; git push
  88. 88. CREDITSdesigned by from The Noun Projectdesigned by from The Noun Projectdesigned by from The Noun Projectdesigned by from The Noun Projectdesigned by from The Noun Projectdesigned by from The Noun Projectdesigned by from The Noun Projectdesigned by from The Noun Projectdesigned by from The Noun Projectdesigned by from The Noun Projectdesigned by from The Noun ProjectLight Bulb Shane David KennaQuestion Anas RamadanHard Disk Drive Eddie AlshehriTime wayne25ukSync P.J. OnoriSync Rohith M SCloud Upload Adam WhitcroftPuzzle John OSheaQuestion Henry RyderFactory Adrijan KaravdicCrash Test Dummy Luis Prado