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...

[Query Builder] Advanced Search

Using the Advanced Search When using a list, select from the 'Build list using' options 'Advanced Search.' This will open a new tab in the list window with one text box labeled: 'Querybuilder Predicate Notation.' This is asking for a few lines of code to define search parameters. Example Code - With Explanations of Results Searching for Pages type=cq:Page property=jcr:content/jcr:title property.value=Places 'type' defines what sort of object you'll be searching for (it's usually a page). 'property' defines what property of the object you'll be filtering by; in this case, its by the title. 'property.value' defines your search term. So this search would be searching all PAGES with the TITLE of PLACES. So it would find every page titled Places. *IMPORTANT* Searches by title ARE case-sensitive, so 'Places' is not the same as 'places'. type=cq:Page path=/cq/sandbox property=jcr:cont...

How to add a new supported language in CQ / WEM (Translator in CQ)

Use case:  You want to add new language to CQ Change display language options in translator grid Change language name and default countries  Solution: You can access translator UI in CQ with following URL http://<HOST>:<PORT>/libs/cq/i18n/translator.html Create new language location for Dictionary Go to CRXDE lite (or your favorite JCR browser) and add this structure (assuming /apps/myapp/i18n as a typical location for custom apps): /apps/myapp/i18n [sling:Folder]     - de [nt:unstructured]         + jcr:mixinTypes = [mix:language]         + jcr:language = de     - fr [nt:unstructured]         + jcr:mixinTypes = [mix:language]         + jcr:language = fr Then reload the translator and the path /apps/ myapp /i18n should show up in the drop-down at the top. Note: the translator will only s...