Jackrabbit
From Resin 3.0
(Difference between revisions)
(New page: == Step by Step (JCA) == 1. Download Resin from http://caucho.com/download 2. Unzip Resin into /usr/local/share/resin 3. Download the JCR API from http://www.day.com/maven/jsr170/jars/jcr...) |
|||
(3 intermediate revisions by one user not shown) | |||
Line 1: | Line 1: | ||
== Step by Step (JCA) == | == Step by Step (JCA) == | ||
− | 1. Download Resin from http://caucho.com/download | + | ''[Tested with Resin 3.1.5 and Jackrabbit 1.4]'' |
− | + | ||
− | + | The JCA deployment style of Jackrabbit integrates Jackrabbit sessions with any Resin transactions, including transactions started by EJBs or <code>UserTransaction</code>. The webapp style of Jackrabbit deployment will work with Resin, but will not automatically be transaction-enabled. | |
− | + | ||
− | + | <ol> | |
− | + | <li>Download Resin from http://caucho.com/download | |
+ | <li>Unzip Resin into /usr/local/share/resin | ||
+ | <li>Download the JCR API from http://www.day.com/maven/jsr170/jars/jcr-1.0.jar | ||
+ | <li>Put the JCR .jar in resin/ext-lib (it will be shared for all web-apps) | ||
+ | <li>Download the jackrabbit .rar file from http://jackrabbit.apache.org/downloads.cgi | ||
+ | <li>Put the jackrabbit .rar in resin/deploy | ||
+ | <li>Make sure resin-support.jar is in resin/ext-webapp-lib (to enable the uri="jackrabbit:" syntax below) | ||
+ | <li>Create a webapp in resin/webapps/jackrabbit | ||
+ | <li>Create or copy a repository.xml to WEB-INF/repository.xml (look inside the .rar for a sample) | ||
+ | <li>Create a resin/webapps/jackrabbit/WEB-INF/resin-web.xml to configure the Jackrabbit session factory: | ||
+ | <code><pre> | ||
+ | <web-app xmlns="http://caucho.com/ns/resin"> | ||
+ | |||
+ | <resource-adapter uri="jackrabbit:"/> | ||
+ | |||
+ | <connection-factory uri="jackrabbit:" name="jcr/test"> | ||
+ | <init> | ||
+ | <home-dir>${webApp.root}/WEB-INF/repository</home-dir> | ||
+ | <config-file>${webApp.root}/WEB-INF/repository.xml</config-file> | ||
+ | </init> | ||
+ | </connection-factory> | ||
+ | |||
+ | <servlet-mapping url-pattern="demo" servlet-class="demo.FirstHopServlet"/> | ||
+ | |||
+ | </web-app> | ||
+ | </pre></code> | ||
+ | |||
+ | <b>Note:</b> you can specify the driver classnames directly (and skip the uri="...") with | ||
+ | |||
+ | <code><pre> | ||
+ | <resource-adapter class="org.apache.jackrabbit.jca.JCAResourceAdapter"/> | ||
+ | |||
+ | <connection-factory class="org.apache.jackrabbit.jca.JCAManagedConnectionFactory"> | ||
+ | </pre></code> | ||
+ | |||
+ | <li>Create a demo servlet to test JCA in WEB-INF/classes/demo/FirstHopServlet.java (Resin will compile the servlet for you): | ||
+ | <code><pre> | ||
+ | package demo; | ||
+ | |||
+ | import java.io.*; | ||
+ | import javax.servlet.*; | ||
+ | import javax.jcr.*; | ||
+ | import javax.webbeans.*; | ||
+ | |||
+ | public class FirstHopServlet extends GenericServlet { | ||
+ | @In private Repository _repository; | ||
+ | |||
+ | public void service(ServletRequest req, ServletResponse res) | ||
+ | throws IOException, ServletException | ||
+ | { | ||
+ | PrintWriter out = res.getWriter(); | ||
+ | |||
+ | try { | ||
+ | testJackrabbit(out); | ||
+ | } catch (Exception e) { | ||
+ | throw new ServletException(e); | ||
+ | } | ||
+ | } | ||
+ | |||
+ | public void testJackrabbit(PrintWriter out) | ||
+ | throws Exception | ||
+ | { | ||
+ | Session session = _repository.login(); | ||
+ | |||
+ | try { | ||
+ | String user = session.getUserID(); | ||
+ | String name = _repository.getDescriptor(Repository.REP_NAME_DESC); | ||
+ | |||
+ | out.println("Logged in " + user + " to " + name + " repository"); | ||
+ | } finally { | ||
+ | session.logout(); | ||
+ | } | ||
+ | } | ||
+ | } | ||
+ | </pre></code> | ||
+ | <li>Start Resin with java -jar resin/lib/resin.jar | ||
+ | <li>Browse http://localhost:8080/jackrabbit | ||
+ | </ol> |
Latest revision as of 20:05, 27 January 2008
[edit] Step by Step (JCA)
[Tested with Resin 3.1.5 and Jackrabbit 1.4]
The JCA deployment style of Jackrabbit integrates Jackrabbit sessions with any Resin transactions, including transactions started by EJBs or UserTransaction
. The webapp style of Jackrabbit deployment will work with Resin, but will not automatically be transaction-enabled.
- Download Resin from http://caucho.com/download
- Unzip Resin into /usr/local/share/resin
- Download the JCR API from http://www.day.com/maven/jsr170/jars/jcr-1.0.jar
- Put the JCR .jar in resin/ext-lib (it will be shared for all web-apps)
- Download the jackrabbit .rar file from http://jackrabbit.apache.org/downloads.cgi
- Put the jackrabbit .rar in resin/deploy
- Make sure resin-support.jar is in resin/ext-webapp-lib (to enable the uri="jackrabbit:" syntax below)
- Create a webapp in resin/webapps/jackrabbit
- Create or copy a repository.xml to WEB-INF/repository.xml (look inside the .rar for a sample)
- Create a resin/webapps/jackrabbit/WEB-INF/resin-web.xml to configure the Jackrabbit session factory:
<web-app xmlns="http://caucho.com/ns/resin"> <resource-adapter uri="jackrabbit:"/> <connection-factory uri="jackrabbit:" name="jcr/test"> <init> <home-dir>${webApp.root}/WEB-INF/repository</home-dir> <config-file>${webApp.root}/WEB-INF/repository.xml</config-file> </init> </connection-factory> <servlet-mapping url-pattern="demo" servlet-class="demo.FirstHopServlet"/> </web-app>
Note: you can specify the driver classnames directly (and skip the uri="...") with
<resource-adapter class="org.apache.jackrabbit.jca.JCAResourceAdapter"/> <connection-factory class="org.apache.jackrabbit.jca.JCAManagedConnectionFactory">
- Create a demo servlet to test JCA in WEB-INF/classes/demo/FirstHopServlet.java (Resin will compile the servlet for you):
package demo; import java.io.*; import javax.servlet.*; import javax.jcr.*; import javax.webbeans.*; public class FirstHopServlet extends GenericServlet { @In private Repository _repository; public void service(ServletRequest req, ServletResponse res) throws IOException, ServletException { PrintWriter out = res.getWriter(); try { testJackrabbit(out); } catch (Exception e) { throw new ServletException(e); } } public void testJackrabbit(PrintWriter out) throws Exception { Session session = _repository.login(); try { String user = session.getUserID(); String name = _repository.getDescriptor(Repository.REP_NAME_DESC); out.println("Logged in " + user + " to " + name + " repository"); } finally { session.logout(); } } }
- Start Resin with java -jar resin/lib/resin.jar
- Browse http://localhost:8080/jackrabbit