|
Developing with Eclipse
This section describes the process of setting up a local development environment for a simple CQ5 project with Eclipse. It then describes how to integrate logic into the project through Java coding and JSP scripting. Lastly, it points to open source software to enable collaborative and automated developing.
Please refer to the corresponding documentation for more information on the different development environments that are available.
The local development environment involves:
A CQ5 installation that will act as your local environment.
CRXDE Lite within the CQ5 instance to create and edit nodes and properties within the CRX repository.
FileVault (VLT), an Adobe-developed utility that maps the CRX repository to your file system.
Eclipse to edit the project source on your local file system.
Apache Maven to run local snapshot builds.
Note
Additionally, you can use the Content Package Maven Plugin with Apache Maven to package and deploy content to the CRX repository. (See Managing Packages Using Maven.)
Creating the Project Structure in CQ5
Create a simple project structure in CQ5:
Install CQ5 on your computer. See Installing CQ5 for the procedure. In the context of this article, CQ5 runs locally on port 4502.
If CQ5 is already installed, ensure it is running and open the Welcome page in your web browser.
Open CRXDE Lite (http://localhost:4502/crx/de/) and create the project structure:
Under the /apps folder, create the nt:folder named myApp.
Under the myApp folder, create the nt:folder named components.
Under the myApp folder, create the nt:folder named templates.
- Under the myApp folder, create the nt:folder named install.
- Click Save All
In your browser, navigate to the Tools page of WCM (http://localhost:4502/miscadmin).
Select the Designs folder, click New, and enter the following property values:
- Click Create.
Installing FileVault (VLT)
FileVault (VLT) maps the content of a CRX instance to your file system. VLT functionalities are similar to those of an SVN client. You can perform check in, check out, and other file-management operations. Configuration options enable flexible representations of project content.
Copy the FileVault archive file from the cq-quickstart/opt/filevault directory of your CQ5 installation. Copy either filevalut.tgz or filevault.zip, depending on your operating system.
You can also download the latest version of FileVault from Daycare.
Extract the archive.
Add <archive-dir>/vault-cli-<version>/bin to your environment PATH so that the command files vlt or vlt.bat are accessed as appropriate. For example, <cq-installation-dir>/crx-quickstart/opt/helpers/vault-cli-2.4.8/bin
Open a command line shell and execute vlt --help. Make sure it displays the following help screen:
--------------------------------------------------------------------------------
Jcr File Vault [version 2.4.8] Copyright 2011 by Adobe Systems Incorporated
--------------------------------------------------------------------------------
Usage:
vlt [options] [arg1 [arg2 [arg3] ..]]
--------------------------------------------------------------------------------
Global options:
-Xjcrlog Extended JcrLog options (omit argument for help)
-Xdavex Extended JCR remoting options (omit argument for
help)
--credentials The default credentials to use
--config The JcrFs config to use
-v (--verbose) verbose output
-q (--quiet) print as little as possible
--version print the version information and exit
--log-level the log4j log level
-h (--help) print this help
Commands:
export Export the Vault filesystem
import Import a Vault filesystem
checkout (co) Checkout a Vault file system
analyze Analyze packages
status (st) Print the status of working copy files and
directories.
update (up) Bring changes from the repository into the working
copy.
info Displays information about a local file.
commit (ci) Send changes from your working copy to the
repository.
revert (rev) Restore pristine working copy file (undo most local
edits).
resolved (res) Remove 'conflicted' state on working copy files or
directories.
propget (pg) Print the value of a property on files or
directories.
proplist (pl) Print the properties on files or directories.
propset (ps) Set the value of a property on files or directories.
add Put files and directories under version control.
delete (del,rm) Remove files and directories from version control.
diff (di) Display the differences between two paths.
rcp Remote copy of repository content.
console Run an interactive console
--------------------------------------------------------------------------------
Eclipse is open-source software that you will use to edit project source files on your file system. Apache Maven is also open source software that compiles Java code and stores the compiled code in a JAR file (snapshot build).
Install Eclipse and a Maven plugin that provides the Maven functionality within Eclipse:
Download Eclipse - select the Eclipse IDE for Java EE Developers option.
Install Eclipse: extract from the downloaded zip file to your destination directory.
Start Eclipse:
Navigate to the directory into which you extracted the contents of the Eclipse installation zip file. For example C:\Program Files\Eclipse\.
Double-click eclipse.exe (or Eclipse.app) to start Eclipse.
In the default workspace, create a new project and name it
myApp.
Install the Maven Integration for Eclipse (m2e) plugin from Eclipse.org. See the instructions at http://marketplace.eclipse.org/content/maven-integration-eclipse.
After installation, restart Eclipse.
Creating the Project Structure in Eclipse
In this section, you create two Maven projects:
-
one called UI (after User Interface) which contains the CQ5
project structure with the JSP scripts.
-
the other called Core which contains the Java code (source and
compiled). The compiled code is stored in a jar file.
The advantage of such a structure is that it adds modularity and
autonomy to the logic of your application because each jar file (bundle)
can be managed separately.
Create the UI Maven Project
Create the UI Maven project:
- In Eclipse, click File > New > Other.
- In the dialog, select Maven > Maven Project and click Next.
- Select the Create a simple project option and the Use default Workspace location option, then click Next.
- Specify the following property values for the Maven project, and accept the default values for all other properties:
Click Finish.
Set the Java Compiler to version 1.5:
In the Project Explorer view, right-click the ui project and click Properties.
Select Java Compiler and set following properties to 1.5:
Click OK.
Create the filter.xml file that defines the content that VLT exports:
In the Project Explorer view, in the ui/src/main folder, create the content folder.
Under content, create the META-INF folder.
Under META-INF, create the vault folder.
Under vault, create the filter.xml file.
In filter.xml, copy the following code to filter.xml:
<?xml version="1.0" encoding="UTF-8"?>
<!-- Defines which repository items are generally included -->
<workspaceFilter version="1.0">
<filter root="/apps/myApp" />
<filter root="/etc/designs/myApp" />
</workspaceFilter>
Save filter.xml.
Use VLT to check out the CQ5 content into your ui project:
In the system command line, change the current directory to the following directory in your Eclipse workspace: <eclipse>/<workspace>/myApp/ui/src/main/content.
Execute the command: vlt --credentials admin:admin co http://localhost:4502/crx
This command creates the folder jcr_root under <eclipse>/<workspace>/myApp/ui/src/main/content. This maps to the CRX root (/). Under jcr_root the following files and folders are created, as defined in filter.xml:
apps/myApp
etc/designs/myApp
It also creates two files, config.xml and settings.xml in <eclipse>/<workspace>/myApp/ui/src/main/content/META-INF/vault. VLT uses these files.
In the ui Eclipse project, create a link to the apps folder that you just checked out. This link enables your JSP scripts to reference the files:
Right-click ui, select New, then Folder.
In the dialog box, click Advanced and select Link to alternate location.
Click Browse, specify <eclipse>/<workspace>/myApp/ui/src/main/content/jcr_root/apps, and then click OK.
Click Finish.
The apps folder appears below the ui project in the Project Explorer view.

Add the CQ and Sling libraries (.jar files) that you require to the Eclipse classpath. Copy the libraries from the repository to a local folder, and add the folder to the Eclipse classpath. In this exercise, you reference the following libraries:
/libs/sling/install
/libs/cq/commons/install
/libs/wcm/core/install
Obtain the libraries using WebDAV:
In your file system, create a CQ5 libraries folder called cq5libs. This folder can be created anywhere.
Map the repository to your file system using a WebDAV client.
Copy all of the .jar files from the following directories to your cq5libs directory:
/libs/sling/install
/libs/cq/commons/install
/libs/wcm/core/install
In Eclipse, right-click the ui project and click Build Path > Configure Build Path. In the dialog select the Libraries tab.
Click Add External JARS, browse to the cq5libs folder and select all the JAR files, then click Open.
Click OK.
Instead of WebDAV, you can use a script. The following script downloads all the libraries from a CQ5 instance. It is for Unix-like systems (such as Mac OS X and Linux) and uses the 'curl' command, but might also succeed running it on Windows with Cygwin (for unix emulation):
#!/bin/sh
[ -z "$CRX_URL" ] && CRX_URL=http://localhost:4502
[ -z "$CRX_CREDENTIALS" ] && CRX_CREDENTIALS=admin:admin
curl -H x-crxde-version:1.0 -H x-crxde-os:mac -H x-crxde-profile:default -u $CRX_CREDENTIALS $CRX_URL/bin/crxde.classpath.xml > .classpath FILE_LIST=`cat .classpath | sed -n '/lib/s/.*WebContent\(.*\)\".*/\1/p'`
for file in $FILE_LIST; do
echo "Downloading $file"
curl -u $CRX_CREDENTIALS $CRX_URL$file -O
done
To run the script:
Open a command line window.
Go to the cq5libs folder.
Create the file classpath.sh with the above content.
Run it with the following command if CQ runs on the default port (4502):
$ sh ./classpath.shor with the following command if CQ runs on a different port:
$ CRX_URL=http://localhost:8080 sh ./classpath.sh
To find out which OSGI bundle contains the package that you need to add to your classpath:
Open the OSGi console and click the Configuration Status tab (http://localhost:4502/system/console/config).
Select the Bundles tab.
- Search for the package in the Exported Packages of the bundles.
Create the Core Maven Project
In Eclipse, create the Core Maven project:
Click File > New > Other.
In the dialog, select Maven > Maven Project and click Next.
Select the Create a simple project option and the Use default Workspace locations option, then click Next.
Specify the following property values, and accept the default values for other properties:
Click Finish.
Add the necessary plugins and dependencies to the core project:
In the Project Explorer view, open the pom.xml file under core.
Click the pom.xml tab at the bottom of the editor, and copy the following code before the closing </project> tag:
<packaging>bundle</packaging>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.5</source>
<target>1.5</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.felix</groupId>
<artifactId>maven-bundle-plugin</artifactId>
<version>1.4.3</version>
<extensions>true</extensions>
<configuration>
<instructions>
<Export-Package> com.day.cq5.myapp.*;version=${project.version} </Export-Package>
</instructions>
</configuration>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>com.day.cq.wcm</groupId>
<artifactId>cq-wcm-api</artifactId>
<version>xxx.xxx.xxx</version>
</dependency>
<dependency>
<groupId>com.day.cq</groupId>
<artifactId>cq-commons</artifactId>
<version>xxx.xxx.xxx</version>
</dependency>
<dependency>
<groupId>org.apache.sling</groupId>
<artifactId>org.apache.sling.api</artifactId>
<version>xxx.xxx.xxx</version>
</dependency>
</dependencies>
Replace the xxx.xxx.xxx versions with the ones available in the CQ version that you are using. For example, for CQ 5.5, use the following bundle versions:
- cq-wcm-api: 5.5.0
- cq-commons: 5.5.0
- org.apache.sling.api: 2.2.4
Tip: To find the current bundle versions use the Configuration Status tab of the OSGi Console (http://localhost:4502/system/console/config).
Save pom.xml.
If the dependencies are not stored in the local Maven repository, compiler errors appear in the pom.xml file.
Note: Perform the following procedure only if the three CQ5 artifacts are not globally deployed for the project on a public Maven repository (such as using Apache Archiva).
Deploy the CQ5-specific artifacts as defined in pom.xml (cq-wcm-api, cq-commons and org.apache.sling.api) to the local Maven repository:
In your file system, copy the file cq-wcm-api-{version}.jar located at cq5libs/wcm (you have created those folders before) into <your-user-dir>/.m2/repository/com/day/cq/wcm/cq-wcm-api/{version} (create the folders if they do not exist).
In your file system, copy the file cq-commons-{version}.jar located at cq5libs/cq (you have created those folders before) into <your-user-dir>/.m2/repository/com/day/cq/cq-commons/{version} (create the folders if they do not exist).
In your file system, copy the file org.apache.sling.api-{version}.jar located at cq5libs/sling (you have created those folders before) into <your-user-dir>/.m2/repository/org/apache/sling/org.apache.sling.api/{version} (create the folders if they do not exist).
Set the Java Compiler to version 1.5:
Right-click the core project, select Properties.
Select Java Compiler and set following properties to 1.5:
Click OK.
In the dialog window, click Yes.
Create the package com.day.cq5.myapp that will contain the Java classes under the core/src/main/java folder:
Under core, right-click the src/main/java folder and click New > Package.
Enter the name com.day.cq5.myapp and click Finish.
Scripting with Eclipse and CQ5
When editing UI code use the following sequence:
Use CRXDE Lite to create a template and a component.
Use VLT to update your file system with the new files.
Use Eclipse to develop the component script (JSP).
Use VLT to check in the changes.
Create a template and a component
- Open CRXDE Lite in your web browser (http://localhost:4502/crx/de/).
- Right-click /apps/myApp/templates and click Create > Create Template.
- Specify the following template properties:
- Label: contentpage
- Title: Content Page
- Resource Type: myApp/components/contentpage
- Click Next.
- Add the following allowed path and click Next.
/content(/.*)?
- Click Next and then click OK.
- Select the /apps/myApp/templates/contentpage/jcr:content node.
- In the Properties tab, add a property:
- Name: personName
- Type: String
- Value: myName
- Click Save All.
- Right-click /apps/myApp/components and click Create > Create Component:
- Label: contentpage
- Title: Content Page
- Super Type: cq:Component
- Click Next, Next, Next, OK.
- Click Save All.
- From the system command line change the current directory to <eclipse>/<workspace>/myApp/ui/src/main/content/jcr_root.
- Execute the following command to see the status of the repository files:
vlt st -v
- Execute the following command to update your file system with the changes in the repository:
vlt up -v
In Eclipse, navigate to ui/src/main/content/jcr_root/apps/myApp/components/contentpage.
You might need to refresh the Project Explorer view to see this folder.
Open contentpage.jsp.
Add the following code as the final line:
This is the contentpage component.
Click File > Save.
From the system command line change the current directory to <eclipse>/<workspace>/myApp/ui/src/main/content/jcr_root.
To see the changes on the file system, execute the following command:
vlt st -v
Execute the following command to commit the changed contentpage.jsp file to the repository:
vlt ci -v
Note
You can define VLT commands as External Tools in Eclipse to run the commands from within Eclipse.
Create a page based on the template
- Open the CQ5 Websites page in your web browser (http://localhost:4502/siteadmin#/content).
- Select the Websites folder and click New > New Page. Provide a title and name for the page, such as My Page, and mypage.
- Select the Content Page template and click Create.
- Open the page and verity that it contains the following text:
This is the contentpage component.
Developing in Java with Eclipse and CQ5
Use the following process to develop code for the core module:
Create and compile a Java class. Package the class in a JAR file that can be deployed to CQ.
Reference the JAR file in the ui project build path.
Add logic to the JSP script so that it uses the Java class.
Use VLT to update the JSP file in the repository.
Use VLT to add and upload the JAR file (with the compiled class) to the repository.
The following example illustrates this process.
Create, compile, and package a Java class
In the core project in Eclipse, under core/src/main/java, right-click the com.day.cq5.myapp package and click New > Class.
Name the class HelloPerson and click Finish.
In HelloPerson.java replace the existing code with the following code:
package com.day.cq5.myapp;
import com.day.cq.wcm.api.Page;
public class HelloPerson {
private Page personPage;
//the name of the page property defined in the contentpage template
public static final String PN_PERSON_NAME = "personName";
public HelloPerson(Page personPage) {
this.personPage = personPage;
}
/*
* Retrieves the PN_PERSON_NAME property from personPage and returns it.
* Checks for null value before returning.
*/
public String getHelloMessage() {
String personName = personPage.getProperties().get(PN_PERSON_NAME).toString();
return personName != null ? personName : "--empty--";
}
}
Save HelloPerson.java.
To compile and package the Java class, right-click the core project and click Run As > Maven Install.
The core-0.0.1-SNAPSHOT.jar file (containing the compiled class) is created and saved in the core/target folder.
Add the core JAR to the ui build path
Add core-0.0.1-SNAPSHOT.jar to the build path of the ui project so that the contentpage.jsp script can use the class:
- In Eclipse, right-click the ui project and click Build Path > Configure Build Path. Then, select the Libraries tab.
Click Add JARS, select core/target/core-0.0.1-SNAPSHOT.jar file, and click OK.
Click OK to close the Java Build Path dialog.
Call the Java class from contentpage.jsp
In Eclipse, open contentpage.jsp from the ui/src/main/content/jcr_root/apps/myApp/components/contentpage folder.
Replace the existing code with the following code:
<%@ page import="com.day.cq5.myapp.HelloPerson" %>
<%@ include file="/libs/foundation/global.jsp" %>
<% HelloPerson hello = new HelloPerson(currentPage);
String msg = hello.getHelloMessage(); %>
Hello, <%= msg %>.</br></br>
This is the contentpage component.
- Save the changes.
- To update the repository, open a system command line window and change the current directory to <eclipse>/<workspace>/myApp/ui/src/main/content/jcr_root.
- To see the changes to the file system, execute the following command:
vlt st -v
- To commit the contentpage.jsp file to the repository, execute the following command:
vlt ci -v
- In Eclipse, under core/target, copy the core-0.0.1-SNAPSHOT.jar file.
- In Eclipse navigate to ui/src/main/content/jcr_root/apps/myapp/install and paste the copied file.
- In the system command line, change the current directory to <eclipse>/<workspace>/myApp/ui/src/main/content/jcr_root.
- To see the changes to the file system, execute the following command:
vlt st -v
To place the JAR file under version control, execute the following command:
vlt add apps/myApp/install/core-0.0.1-SNAPSHOT.jar -v
To commit the JAR file to the repository, execute the following command:
vlt ci -v
- In your web browser, refresh the CQ5 page and ensure that it displays the following message:
Hello, myName.
This is the contentpage component.
- In CRXDE Lite, select the /apps/myApp/templates/contentpage/jcr:content node and change the value of the personName property.
- Save the changes and refresh the web page and verify that the new value appears.
Building collaborative and automated projects
This section points to three open source software projects that enhance the development of CQ5 projects by adding collaboration and automation features:
-
Subversion (SVN) to manage a central repository where all the
developers involved in the project can commit and retrieve the code
and the content they generate on their local instance.
-
Apache Archiva to centrally store and retrieve the project
libraries.
-
Apache Continuum to automate the build process.
Collaboration with Subversion (SVN)
As the CQ5 repository can be mapped to your file system with VLT, it is now easy to set up a central repository with SVN. This is used by all developers in the project as a place they can commit, and retrieve, the code and content they generate on their local instances.
The setup of an SVN server is not covered in this document as many tutorials are already available online.
When VLT is in operation it creates .vlt files within the local directory structure. These .vlt files hold timestamps and other VLT-specific information that should not be checked into the SVN repository. This can be prevented by adding .vlt to the ignore list of the local SVN setup. To do this you add the following code to the local SVN setup file - settings.xml in the .subversion directory of your user's HOME directory:
[miscellany] ### Set global-ignores to a set of whitespace-delimited globs ### which Subversion will ignore in its 'status' output, and ### while importing or adding files and directories. global-ignores = .vlt
Central dependency management with Apache Archiva
Java libraries, called artifacts in Maven language, can be managed centrally through Apache Archiva, an artifact repository that is used to store and retrieve the project artifacts. The setup of Archiva is well detailed online and can be referenced during setup. The Archiva server requires little management outside that of configuring local developer accounts to obtain access to the snapshots and full releases. Archiva can be found here.
When setting up Archiva for a CQ project the only step that is specific to CQ itself is initially populating the repository with the artifacts needed for CQ development. To acquire the full set of libraries you can use the same method as described above in point #7 of Create The UI Maven Project.
You can use the same script as shown there (and reproduced here):
#!/bin/sh
[ -z "$CRX_URL" ] && CRX_URL=http://localhost:4502 [ -z "$CRX_CREDENTIALS" ] && CRX_CREDENTIALS=admin:admin
curl -H x-crxde-version:1.0 -H x-crxde-os:mac -H x-crxde-profile:default -u $CRX_CREDENTIALS $CRX_URL/bin/crxde.classpath.xml > .classpath FILE_LIST=`cat .classpath | sed -n '/lib/s/.*WebContent\(.*\)\".*/\1/p'` for file in $FILE_LIST; do echo "Downloading $file" curl -u $CRX_CREDENTIALS $CRX_URL$file -O done
This script simply downloads all the libraries from your CQ installation. By deploying these libraries to your Archiva repository, you can make them available to your whole development team. To deploy the downloaded files to Archiva, see the Archiva documentation here.
Build automation with Apache Continuum
Once the project content and code is centrally available through an SVN server, it is possible to automate the build process and run the build on a daily basis (for example a nightly build). This is done with Apache Continuum, a continuous integration server with the sole duty of providing build management of artifacts and releases.
The setup of Continuum is also well detailed online.
|
|
"Create a new workspace for your project and name it myApp".
Be clear to say:
In the default workspace, create a new project and name it myApp
We are changing our distribution method and will let you know when the new file vault version will be available.
For the time, you can use the vlt version that is shipped with your cq installation (see crx-quickstart/opt/filevault folder).
Alex.
Hope that helps.
Alex
We are trying to setup build & release management setup for CQ (UI & Core project listed in this article).
Last para briefly talk about this, but not in detail.
It would be very helpful , if you could you please point me to articles/case studies which talks about this in detail
Thanks,
1. How the UI project described in the article is deployed across environments (just export from svn to local & use vlt to upload to the repository?) or is there a way to deploy as an artifact
2. For deploying core project across environment. The deploy script just has to copy the snapshot jar into repository's /app/myapp/install? (vlt add apps/myApp/install/core-0.0.1-SNAPSHOT.jar -v).
2.a Does this require restart
2.b Is there a mechanism to deploy as OSGI bundle
3. In what context, package share is used to move CQ artifact acorss enviroment
a Does this require restart, when jars are moved using content packages
b Is there a command line option to export/import content packages (vlt?)
c Is there a mechanism to deploy the jars as OSGI bundle
a. it doesn't require a restart, as it uses the OSGI framework's dynamicity.
b. please read: http://dev.day.com/content/docs/en/cq/current/core/how_to/package_manager.html
c. see above
Shouldn't it be 1.6 for CQ5.5?
http://dev.day.com/docs/en/cq/current/deploying/technical_requirements.html
Hope that helps.
Note: Customers with DayCare user accounts need to create a new account for use on day.com.