I'm trying to setup a JNDI resource for a Jackrabbit repository factory in Jetty. The problem is that I seem to be getting thhe JNDI as webapp scoped. I need it to be JVM scoped. As far as I understood from the docs, you need to specify a null arg as shown below (<Arg></Arg>
) in order to do so (explained here).
I have two webapps deployed to Jetty and I need them to be sharing the same JNDI. If they're not sharing it, Jackrabbit tries to get initialized twice and fails which breaks my whole app.
I ran the code through a debugger and I can see that the first webapp that gets accessed and needs a JNDI lookup for the Jackrabbit repository, gets an instance of the BindableRepositoryFactory
and correctly adds records to the cache
object. However, a completely different object is created for the cache
upon JNDI lookup. That is obviously still empty and thus a new instance gets created, which screws things up.
I am using Jetty 7.6.2.v20120308. Here's my jetty-jndi.xml:
<New class="org.eclipse.jetty.plus.jndi.Resource">
<Arg></Arg>
<Arg>jndi:comp/env/jcr/repository</Arg>
<Arg>
<New class="javax.naming.Reference" id="reference">
<Arg>javax.jcr.Repository</Arg>
<Arg>org.apache.jackrabbit.core.jndi.BindableRepositoryFactory</Arg>
<Arg>null</Arg>
<Call name="add" id="reference">
<Arg>
<New class="javax.naming.StringRefAddr">
<Arg>configFilePath</Arg>
<Arg><SystemProperty name="jetty.home" default="."/>/jackrabbit/repository.xml</Arg>
</New>
</Arg>
</Call>
<Call name="add" id="reference">
<Arg>
<New class="javax.naming.StringRefAddr">
<Arg>repHomeDir</Arg>
<Arg><SystemProperty name="jetty.home" default="."/>/jackrabbit</Arg>
</New>
</Arg>
</Call>
</New>
</Arg>
</New>
In the pom file where I'm invoking jetty from, I have the following relevant settings that tell Jetty to use the JNDI and Plus settings xml-s:
<jettyConfig>${project.build.directory}/jetty/etc/jetty-plus.xml,${project.build.directory}/jetty/etc/jetty-jndi.xml</jettyConfig>
In the jetty-plus.xml I have:
<!-- =========================================================== -->
<!-- Sequence of configurations to defining Plus features. -->
<!-- =========================================================== -->
<Array id="plusConfig" type="java.lang.String">
<Item>org.eclipse.jetty.webapp.WebInfConfiguration</Item>
<Item>org.eclipse.jetty.webapp.WebXmlConfiguration</Item>
<Item>org.eclipse.jetty.webapp.MetaInfConfiguration</Item>
<Item>org.eclipse.jetty.webapp.FragmentConfiguration</Item>
<Item>org.eclipse.jetty.plus.webapp.EnvConfiguration</Item> <!-- Add for JNDI -->
<Item>org.eclipse.jetty.plus.webapp.PlusConfiguration</Item> <!-- Add for JNDI -->
<Item>org.eclipse.jetty.annotations.AnnotationConfiguration</Item>
<Item>org.eclipse.jetty.webapp.JettyWebXmlConfiguration</Item>
<Item>org.eclipse.jetty.webapp.TagLibConfiguration</Item> <!-- Not needed for Jetty-8 -->
</Array>
<!-- =========================================================== -->
<!-- Apply plusConfig to all webapps for this Server -->
<!-- =========================================================== -->
<Call name="setAttribute">
<Arg>org.eclipse.jetty.webapp.configuration</Arg>
<Arg>
<Ref id="plusConfig"/>
</Arg>
</Call>
Any ideas what I might be doing wrong?
Many thanks in advance! :)
This appears to be a bug in Jetty's global JNDI resource configuration.
I have filed a bug in Jetty's bugzilla and will accept this answer as correct, despite the fact it is no solution.