jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From conflue...@apache.org
Subject [CONF] Apache Jackrabbit: Embedded Repository (page edited)
Date Mon, 05 Jan 2009 14:18:00 GMT
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


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.


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.


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.

+- 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:
+- 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

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.

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);

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.


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

This message is automatically generated by Confluence

Unsubscribe or edit your notifications preferences

If you think it was sent incorrectly contact one of the administrators

If you want more information on Confluence, or have a bug to report see

View raw message