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
Đăng nhận xét