JCR client application HOWTO
This document describes the common configuration and initialization code of a client application that uses a JCR content repository. The application setup does not depend on the underlying deployment model, implementation, or configuration of the content repository.
The instructions in this document apply to a J2EE web application that uses JNDI to access the content repository. It should however be easy to modify the instructions for other container environments.
Follow the steps below to access a JNDI-bound content repository within a J2EE web application. Example code is included after this overview. See the deployment model howtos for instructions on how to create the JNDI bindings for the standard deployment models.
- Place the JCR API jar in the WEB-INF/lib subdirectory of your web application.
- Declare the JNDI address under which you will request the repository instance in the deployment descriptor.
- Code your application to use the resource.
Note that that none of your code or configuration needs to depend on the underlying repository implementation or deployment model. All those details are handled by the container and can easily be changed without modifying your application. Just make sure that you have documented the JCR repository level and optional features your application requires so that your application can be deployed in an appropriate environment.
Add the following snippet in your web.xml deployment descriptor to declare your application's use of a content repository resource.
Note that the java:comp/env/jcr subcontext is the preferred naming context for JCR content repository resources.
Use the following Java code snippet to get a reference to the configured content repository instance.