Chuyển đến nội dung chính

[MAVEN] Using Maven to Create and Install CQ5 Package

Creating components using CRXDE and CRXDE Lite can be frustrating. Both are buggy and are different environments than what you are use to working with. You can use Maven to create a package that it can then install the package in CQ5.
If you have ever extracted a package then you’ll see that there are two folders within it, jcr_root and META-INF. Both of these files are important and they determine how the Maven project should be setup. META-INF holds the filters (paths) that the package contains. jcr_root has all of your files for components, templates, etc. I typically put these files in src/main/content in the Maven project so my code will have that path.
First thing you need to do is in pom.xml under <build> add the following code so that it knows to include your files in the bundle. This also excludes any file vault (VLT) files.

<resources>
   <!-- filter meta information to get some properties into the files -->
   <resource>
   <directory>${basedir}/src/main/content/META-INF</directory>
   <targetPath>META-INF</targetPath>
   <filtering>true</filtering>
   </resource>
   <!-- exclude .vlt control files and tests -->
   <resource>
   <directory>${basedir}/src/main/content/jcr_root</directory>
   <excludes>
   <exclude>**/.vlt</exclude>
   <exclude>**/.vltignore</exclude>
   <exclude>**/.DS_Store</exclude>
   </excludes>
   <targetPath>jcr_root</targetPath>
   </resource>
</resources>

Next you need to setup a profile that uses Groovy to install the package to CQ5 using POST.

<profile>
   <id>installPackage</id>
   <activation>
   <property>
   <name>installPackage</name>
   </property>
   </activation>
   <properties>
   <hostname>http://localhost</hostname>
   <hostport>4502</hostport>
   <publishhostname>http://localhost</publishhostname>
   <publishhostport>4503</publishhostport>
   <packageName>${artifactId}-${version}</packageName>
   <cquser>admin</cquser>
   <cqpassword>admin</cqpassword>
   <showUpload>true</showUpload>
   <showInstall>true</showInstall>
   <projectDir>${basedir}</projectDir>
   </properties>
   <build>
   <plugins>
   <plugin>
   <groupId>org.codehaus.gmaven</groupId>
   <artifactId>gmaven-plugin</artifactId>
   <version>1.2</version>
   <dependencies>
   <dependency>
   <groupId>org.codehaus.gmaven.runtime</groupId>
   <artifactId>gmaven-runtime-1.7</artifactId>
   <version>1.2</version>
   </dependency>
   <dependency>
   <groupId>commons-httpclient</groupId>
   <artifactId>commons-httpclient</artifactId>
   <version>3.1</version>
   </dependency>
   <dependency>
   <groupId>commons-logging</groupId>
   <artifactId>commons-logging</artifactId>
   <version>1.1.1</version>
   <type>jar</type>
   <scope>compile</scope>
   </dependency>
   </dependencies>
   <executions>
   <execution>
   <phase>install</phase>
   <goals>
   <goal>execute</goal>
   </goals>
   <configuration>
   <defaults>
   <cqservers>localhost:4502</cqservers>
   <cquser>admin</cquser>
   <cqpassword>admin</cqpassword>
   <packageName>${artifactId}-${version}</packageName>
   <projectDir>${basedir}</projectDir>
   </defaults>
   <source>
   import org.apache.commons.httpclient.*
   import org.apache.commons.httpclient.methods.*
   import org.apache.commons.httpclient.auth.*
   import org.apache.commons.httpclient.methods.multipart.*

   //method declaration for execute of PostMethod
   def executePost(httpclient, httppost, outputResponse){
   try {
   httpclient.executeMethod(httppost);
   if (outputResponse){
   println httppost.responseBodyAsString
   }
   } catch (Exception e) {
   println("exception: " + e)
   } finally {
   httppost.releaseConnection()
   }
   }

   def uploadAndInstall(hostPort, packageName, projectRoot, httpclient){
   //upload package
   def httppost = new PostMethod('http://' + hostPort + '/crx/packmgr/service.jsp')
   def file = new File(projectRoot + '/target/' + packageName + '.jar')

   println("Installing package" +packageName+" to " + hostPort)

   if(file.exists()){

   def parts = [new FilePart("file", file)] as Part[]
   httppost.setRequestEntity(new MultipartRequestEntity(parts,
   httppost.getParams()))

   executePost(httpclient, httppost, true)

   //install package
   def installURL = 'http://' + hostPort +
   '/crx/packmgr/service/.json/etc/packages/' + packageName + '.zip'
   println('INASTALL: ' + installURL)
   httppost = new PostMethod(installURL)
   httppost.addParameter("cmd", "install")

   executePost(httpclient, httppost, true)
   } else {
   println("File does not exist for " + packageName + ". Not Deploying.")
   }
   }

   def user = project.properties['cquser']
   def pass = project.properties['cqpassword']
   def packageName = project.properties['packageName']
   def projectRoot = project.properties['projectDir']

   // set up the client
   def httpclient = new HttpClient()
   def defaultcreds = new UsernamePasswordCredentials(user, pass)
   httpclient.getState().setCredentials(AuthScope.ANY, defaultcreds)
   httpclient.getParams().setAuthenticationPreemptive(true)

   println "CQSERVERS:" + project.properties['cqservers']

   project.properties['cqservers'].tokenize(',').each {
   uploadAndInstall(it, packageName, projectRoot, httpclient)
   }

   </source>
   </configuration>
   </execution>
   </executions>
   </plugin>
   <!-- Compile Java classes for OSGi bundle -->
   <plugin>
   <groupId>org.apache.maven.plugins</groupId>
   <artifactId>maven-compiler-plugin</artifactId>
   </plugin>
   </plugins>
   </build>
</profile>

When building the project make sure you select the installPackage profile or if you are using the command line add the argument -DinstallPackage and it will automatically install the package into CQ5.

From ericfaerber.wordpress.com

Nhận xét

Bài đăng phổ biến từ blog này

[PERFORMANCE] Adobe WEM/CQ performance tuning

Adobe WEM/CQ performance tuning Contents Caching-related configurations CRX Bundle cache CRX Search index handler (Lucene) cache Tar PM index cache Scalability Maintenance Optimizing Tar Files (for Tar Persistence Manager) Data Store Garbage Collection Main documentation you should consult first: http://dev.day.com/docs/en/cq/current/deploying/performance.html http://dev.day.com/content/kb/home/cq5/CQ5Troubleshooting/performancetuningtips.html Caching-related configurations CRX Bundle cache CRX caches bundles, consisting of a node with all its properties. This is used by all bundle-based Persistence Managers. The default size of BundleCache is 8 MB. If this is too small it can cause an excessive number of read-accesses to the underlying persistence layer. Set the bundleCacheSize to something larger than the default. See more here: http://dev.day.com/docs/en/cq/current/deploying/performance.html#CRX%20Bundle%20Cache CRX Search index handler (Lucene...

How to custom CQ Login Module

In order to manage the login process in our project, we will use a custom CQ Login Module. We will admit the root URL of CQ instance is: http://localhost:4502/ . This value may change depending of your environment. The %CQ_HOME% variable we will mention refers to the CQ install path. It admits you have defined %CQ_HOME% as an environment variable. 1.         Update the repository definitions The login module must be referenced in the repository definitions. You have to edit the next file: %CQ_HOME%/crx-quickstart/repository/repository.xml Do a copy of repository.xml to repository.xml.original In repostiory.xml, replace  security  part of repository.xml with following: <Security appName="com.day.crx">         <SecurityManager class="com.day.crx.core.CRXSecurityManager"> <WorkspaceAccessManager class="org.apache.jackrabbit.core.security.simple.SimpleWorkspaceAccessManager"/>  ...

[DAM] Custom DAM management / Add 'Alt' into images

Issue: We need, for each asset to be able to edit the ‘alt’ text. The ‘alt’ text must be used on the site each time an asset is displayed. When displaying an asset, the mechanism is the following : -       Get the Locale from the request -       When getting the asset, get the associated Alt property corresponding to the locale. -       Populate the alt attribute with this value. Resolution: To achieve this, we can customize the DAM Asset Editor. The AssetEditor is the form used to input asset properties and metadata. Below is a screenshot of a customized form with four “alt” input (for four different locales). The DAM uses the following nodes to render Asset Editor forms: -       /libs/dam/content/asseteditors/formitems -       /libs/dam/content/asseteditors/images/formitems -      ...