J'ai déployé Jackrabbit dans Tomcat 7 en utilisant le modèle 2 (Shared J2EE Resource), mais lorsque j'essaie d'accéder au référentiel, j'obtiens l'exception NamingException
.NamingException: Impossible de créer une instance de ressource avec Jackrabbit dans Tomcat
javax.naming.NamingException: Cannot create resource instance
at org.apache.naming.factory.ResourceFactory.getObjectInstance(ResourceFactory.java:144)
at javax.naming.spi.NamingManager.getObjectInstance(Unknown Source)
at org.apache.naming.NamingContext.lookup(NamingContext.java:842)
at org.apache.naming.NamingContext.lookup(NamingContext.java:153)
at org.apache.naming.NamingContext.lookup(NamingContext.java:830)
at org.apache.naming.NamingContext.lookup(NamingContext.java:167)
Mon code est:
InitialContext context = new InitialContext();
Context environment = (Context) context.lookup("java:comp/env");
// The exception is thrown in this line
Repository repository = (Repository) environment.lookup("jcr/repository");
J'ai ajouté cette ressource en tant que GlobalNamingResource
dans mon Tomcat server.xml
:
<Resource name="jcr/globalRepository"
auth="Container"
type="javax.jcr.Repository"
factory="org.apache.jackrabbit.core.jndi.BindableRepositoryFactory"
configFilePath="C:\Users\vgomez\repository.xml"
repHomeDir="C:\Users\vgomez\repository"/>
En context.xml
j'ai ajouté le ResourceLink
:
<ResourceLink
name="jcr/repository"
global="jcr/globalRepository"
type="javax.jcr.Repository"/>
Et la web.xml
de mon application web est:
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd"
version="2.4">
<display-name>Archetype Created Web Application</display-name>
<resource-ref>
<description>JCR Repository</description>
<res-ref-name>jcr/repository</res-ref-name>
<res-type>javax.jcr.Repository</res-type>
<res-auth>Container</res-auth>
</resource-ref>
</web-app>
Edit: Ce problème apparaît lorsque l'application Web utilise Vaadin. Si l'application web utilise jsf par exemple cette configuration fonctionne.