You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@jackrabbit.apache.org by co...@apache.org on 2009/01/05 15:18:00 UTC

[CONF] Apache Jackrabbit: Embedded Repository (page edited)

Embedded Repository (JCR) edited by Jukka Zitting
      Page: http://cwiki.apache.org/confluence/display/JCR/Embedded+Repository
   Changes: http://cwiki.apache.org/confluence/pages/diffpagesbyversion.action?pageId=106665&originalVersion=2&revisedVersion=3






Content:
---------------------------------------------------------------------

You can run Jackrabbit in embedded mode inside your application if you only (or mostly) access a repository from that one application. In this deployment model the Jackrabbit dependencies are included directly in your classpath and your application is in full control of the repository lifecycle. To use this deployment model you need to add the appropriate dependencies to your application and include a few lines of Jackrabbit-specific code to start and stop a repository. You can then use the standard JCR API to access and manage content inside the repository.

{toc:minLevel=2}

h2. Maven dependencies

To use Jackrabbit in embedded mode you need to make sure that the JCR API and all required Jackrabbit libraries are included in your classpath. If you use [Maven 2|http://maven.apache.org/], you can achieve this by specifying the following dependencies.

{code:xml}
<dependency>
  <groupId>javax.jcr</groupId>
  <artifactId>jcr</artifactId>
  <version>1.0</version>
</dependency>
<dependency>
  <groupId>org.apache.jackrabbit</groupId>
  <artifactId>jackrabbit-core</artifactId>
  <version>1.5.0</version>
  <exclusions>
    <exclusion>
      <groupId>commons-logging</groupId>
      <artifactId>commons-logging</artifactId>
    </exclusion>
  </exclusions>
</dependency>
<dependency>
  <groupId>org.slf4j</groupId>
  <artifactId>jcl-over-slf4j</artifactId>
  <version>1.5.3</version>
</dependency>
<dependency>
  <groupId>org.slf4j</groupId>
  <artifactId>slf4j-log4j12</artifactId>
  <version>1.5.3</version>
</dependency>
{code}

The jcr dependency includes the JCR 1.0 API in your classpath. You need to explicitly declare this dependency as in jackrabbit-core the JCR API dependency scope is _provided_ to work better in deployment models where the JCR API is shared between multiple applications.

The jackrabbit-core dependency pulls in the Jackrabbit content repository implementation and a set of transitive dependencies needed by Jackrabbit. See the [Downloads] page for the latest available version.

Jackrabbit uses the [SLF4J|http://www.slf4j.org/] for logging and leaves it up to the embedding application to decide which underlying logging library to use. In the example above we use the slf4j-log4j12 library which uses [log4j 1.2|http://logging.apache.org/log4j/1.2/] for handling the log messages. Note that the commons-logging dependency (which is a transitive dependency from [Apache POI|http://poi.apache.org/]) is explicitly replaced with the jcl-over-slf4j dependency that routes also all [Commons Logging|http://commons.apache.org/logging/] log messages through the selected SLF4J implementation. Jackrabbit 1.5.x uses SLF4J version 1.5.3.

The full set of compile-scope dependencies included by the above declaration is shown below. If you use a build tool like [Ant|http://ant.apache.org/] where you need to explicitly include all dependencies, you can use this list to correctly configure your classpath.

{code}
+- javax.jcr:jcr:jar:1.0:compile
+- org.apache.jackrabbit:jackrabbit-core:jar:1.5.0:compile
|  +- concurrent:concurrent:jar:1.3.4:compile
|  +- commons-collections:commons-collections:jar:3.1:compile
|  +- commons-io:commons-io:jar:1.4:compile
|  +- org.apache.jackrabbit:jackrabbit-api:jar:1.5.0:compile
|  +- org.apache.jackrabbit:jackrabbit-jcr-commons:jar:1.5.0:compile
|  +- org.apache.jackrabbit:jackrabbit-spi-commons:jar:1.5.0:compile
|  +- org.apache.jackrabbit:jackrabbit-spi:jar:1.5.0:compile
|  +- org.apache.jackrabbit:jackrabbit-text-extractors:jar:1.5.0:compile
|  |  +- org.apache.poi:poi:jar:3.0.2-FINAL:compile
|  |  +- org.apache.poi:poi-scratchpad:jar:3.0.2-FINAL:compile
|  |  +- pdfbox:pdfbox:jar:0.7.3:compile
|  |  |  +- org.fontbox:fontbox:jar:0.1.0:compile
|  |  |  \- org.jempbox:jempbox:jar:0.2.0:compile
|  |  \- net.sourceforge.nekohtml:nekohtml:jar:1.9.7:compile
|  |     \- xerces:xercesImpl:jar:2.8.1:compile
|  |        \- xml-apis:xml-apis:jar:1.3.03:compile
|  +- org.slf4j:slf4j-api:jar:1.5.3:compile
|  +- org.apache.lucene:lucene-core:jar:2.3.2:compile
|  \- org.apache.derby:derby:jar:10.2.1.6:compile
+- org.slf4j:jcl-over-slf4j:jar:1.5.3:compile
\- org.slf4j:slf4j-log4j12:jar:1.5.3:compile
   \- log4j:log4j:jar:1.2.14:compile
{code}

Note that some of the transitive dependencies listed above may conflict with some other dependencies of our application. In such cases you may want to consider switching to a deployment model that uses separate class loaders for your application and the Jackrabbit content repository.

h2. Starting the repository

Once you have your classpath configured you can start the repository with the following piece of code.

{code:java}
import org.apache.jackrabbit.core.RepositoryImpl;
import org.apache.jackrabbit.core.config.RepositoryConfig;

String xml = "/path/to/repository/configuration.xml";
String dir = "/path/to/repository/directory";
RepositoryConfig config = RepositoryConfig.create(xml, dir);
RepositoryImpl repository = RepositoryImpl.create(config);
{code}

See the [Jackrabbit Configuration] page for more information on repository configuration. See the [RepositoryConfig|http://jackrabbit.apache.org/api/1.5/org/apache/jackrabbit/core/config/RepositoryConfig.html] and [RepositoryImp|http://jackrabbit.apache.org/api/1.5/org/apache/jackrabbit/core/RepositoryImpl.html] javadocs for more details on these classes.

h2. Shutting down the repository

When your application no longer needs the content repository, you can shut it down with the following code.

{code:java}
repository.shutdown();
{code}

This will forcibly close all open sessions and make sure that all repository content is safely stored on disk.


---------------------------------------------------------------------
CONFLUENCE INFORMATION
This message is automatically generated by Confluence

Unsubscribe or edit your notifications preferences
   http://cwiki.apache.org/confluence/users/viewnotifications.action

If you think it was sent incorrectly contact one of the administrators
   http://cwiki.apache.org/confluence/administrators.action

If you want more information on Confluence, or have a bug to report see
   http://www.atlassian.com/software/confluence