2015-11-13 1 views
1

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.

Répondre

0

J'ai trouvé le problème. Je pense que je n'avais pas toutes les dépendances nécessaires. Pour un projet Vaadin créée en utilisant l'COMAND donnée dans le Book of Vaadin c'est le pom.xml

<?xml version="1.0" encoding="UTF-8"?> 
    <project xmlns="http://maven.apache.org/POM/4.0.0" 
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 
    http://maven.apache.org/xsd/maven-4.0.0.xsd"> 
<modelVersion>4.0.0</modelVersion> 

<groupId>com.example</groupId> 
<artifactId>jackrabbitVaadin</artifactId> 
<packaging>war</packaging> 
<version>1.0</version> 
<name>jackrabbitVaadin</name> 

<properties> 
    <vaadin.version>7.5.9</vaadin.version> 
    <vaadin.plugin.version>${vaadin.version}</vaadin.plugin.version> 
    <jetty.plugin.version>9.2.3.v20140905</jetty.plugin.version> 
    <project.source.version>1.7</project.source.version> 
    <project.target.version>1.7</project.target.version> 
    <project.encoding>UTF-8</project.encoding> 
</properties> 

<repositories> 
    <repository> 
     <id>vaadin-addons</id> 
     <url>http://maven.vaadin.com/vaadin-addons</url> 
    </repository> 
    <repository> 
     <id>vaadin-snapshots</id> 
     <url>https://oss.sonatype.org/content/repositories/vaadin-snapshots/</url> 
     <releases> 
      <enabled>false</enabled> 
     </releases> 
     <snapshots> 
      <enabled>true</enabled> 
     </snapshots> 
    </repository> 
</repositories> 

<dependencyManagement> 
    <dependencies> 
     <dependency> 
      <groupId>com.vaadin</groupId> 
      <artifactId>vaadin-bom</artifactId> 
      <version>${vaadin.version}</version> 
      <type>pom</type> 
      <scope>import</scope> 
     </dependency> 
    </dependencies> 
</dependencyManagement> 

<dependencies> 
    <dependency> 
     <groupId>org.ow2.asm</groupId> 
     <artifactId>asm</artifactId> 
     <version>5.0.3</version> 
     <scope>compile</scope> 
    </dependency> 
    <dependency> 
     <groupId>javax.servlet</groupId> 
     <artifactId>javax.servlet-api</artifactId> 
     <version>3.0.1</version> 
     <scope>provided</scope> 
    </dependency> 
    <dependency> 
     <groupId>com.vaadin</groupId> 
     <artifactId>vaadin-server</artifactId> 
    </dependency> 
    <dependency> 
     <groupId>com.vaadin</groupId> 
     <artifactId>vaadin-push</artifactId> 
    </dependency> 
    <dependency> 
     <groupId>com.vaadin</groupId> 
     <artifactId>vaadin-client</artifactId> 
     <scope>provided</scope> 
    </dependency> 

    <dependency> 
     <groupId>javax.jcr</groupId> 
     <artifactId>jcr</artifactId> 
     <version>2.0</version> 
    </dependency> 
    <dependency> 
     <groupId>org.apache.jackrabbit</groupId> 
     <artifactId>jackrabbit-core</artifactId> 
     <version>2.8.1</version> 
     <scope></scope> 
    </dependency> 
    <dependency> 
     <groupId>org.apache.jackrabbit</groupId> 
     <artifactId>jackrabbit-jcr-rmi</artifactId> 
     <version>1.4</version> 
    </dependency> 
    <dependency> 
     <groupId>org.apache.jackrabbit</groupId> 
     <artifactId>jackrabbit-jcr-server</artifactId> 
     <version>1.4</version> 
    </dependency> 
    <dependency> 
     <groupId>org.apache.jackrabbit</groupId> 
     <artifactId>jackrabbit-webapp</artifactId> 
     <version>1.4</version> 
    </dependency> 
    <dependency> 
     <groupId>org.slf4j</groupId> 
     <artifactId>slf4j-api</artifactId> 
     <version>1.7.5</version> 
    </dependency> 
    <dependency> 
     <groupId>org.slf4j</groupId> 
     <artifactId>slf4j-log4j12</artifactId> 
     <version>1.7.5</version> 
    </dependency> 
    <dependency> 
     <groupId>commons-collections</groupId> 
     <artifactId>commons-collections</artifactId> 
     <version>3.2.1</version> 
    </dependency> 
    <dependency> 
     <groupId>xerces</groupId> 
     <artifactId>xercesImpl</artifactId> 
     <version>2.8.1</version> 
    </dependency> 
    <dependency> 
     <groupId>javax.servlet</groupId> 
     <artifactId>servlet-api</artifactId> 
     <version>2.4</version> 
     <scope>provided</scope> 
    </dependency> 
    <dependency> 
     <groupId>javax.servlet</groupId> 
     <artifactId>jsp-api</artifactId> 
     <version>2.0</version> 
     <scope>provided</scope> 
    </dependency> 
    <dependency> 
     <groupId>com.oracle</groupId> 
     <artifactId>ojdbc14</artifactId> 
     <version>10.2.0.5.0</version> 
    </dependency> 
    <!-- Needed when using the widgetset optimizer (custom ConnectorBundleLoaderFactory). 
     For widgetset compilation, vaadin-client-compiler is automatically added 
     on the compilation classpath by vaadin-maven-plugin so normally there is 
     no need for an explicit dependency. --> 
    <!-- <dependency> <groupId>com.vaadin</groupId> <artifactId>vaadin-client-compiler</artifactId> 
     <scope>provided</scope> </dependency> --> 
    <dependency> 
     <groupId>com.vaadin</groupId> 
     <artifactId>vaadin-themes</artifactId> 
    </dependency> 
</dependencies> 

<build> 
    <plugins> 
     <plugin> 
      <groupId>org.apache.maven.plugins</groupId> 
      <artifactId>maven-compiler-plugin</artifactId> 
      <version>3.0</version> 
      <configuration> 
       <encoding>${project.encoding}</encoding> 
       <source>${project.source.version}</source> 
       <target>${project.target.version}</target> 
      </configuration> 
     </plugin> 
     <plugin> 
      <groupId>org.apache.maven.plugins</groupId> 
      <artifactId>maven-resources-plugin</artifactId> 
      <version>2.6</version> 
      <configuration> 
       <encoding>${project.encoding}</encoding> 
      </configuration> 
     </plugin> 
     <plugin> 
      <groupId>org.apache.maven.plugins</groupId> 
      <artifactId>maven-war-plugin</artifactId> 
      <version>2.3</version> 
      <configuration> 
       <failOnMissingWebXml>false</failOnMissingWebXml> 
       <!-- Exclude some unnecessary files generated by the GWT compiler. --> 
       <packagingExcludes>WEB-INF/classes/VAADIN/gwt-unitCache/**, 
        WEB-INF/classes/VAADIN/widgetsets/WEB-INF/**</packagingExcludes> 
      </configuration> 
     </plugin> 
     <plugin> 
      <groupId>com.vaadin</groupId> 
      <artifactId>vaadin-maven-plugin</artifactId> 
      <version>${vaadin.plugin.version}</version> 
      <configuration> 
       <extraJvmArgs>-Xmx512M -Xss1024k</extraJvmArgs> 
       <webappDirectory>${basedir}/target/classes/VAADIN/widgetsets</webappDirectory> 
       <draftCompile>false</draftCompile> 
       <compileReport>false</compileReport> 
       <style>OBF</style> 
       <strict>true</strict> 
      </configuration> 
      <executions> 
       <execution> 
        <goals> 
         <goal>update-theme</goal> 
         <goal>update-widgetset</goal> 
         <goal>compile</goal> 
         <!-- disabled by default to use on-the-fly theme compilation --> 
         <!-- <goal>compile-theme</goal> --> 
        </goals> 
       </execution> 
      </executions> 
     </plugin> 
     <plugin> 
      <groupId>org.apache.maven.plugins</groupId> 
      <artifactId>maven-source-plugin</artifactId> 
      <version>2.4</version> 
     </plugin> 
     <plugin> 
      <groupId>org.apache.maven.plugins</groupId> 
      <artifactId>maven-clean-plugin</artifactId> 
      <version>2.6.1</version> 
      <!-- Clean up also any pre-compiled themes --> 
      <configuration> 
       <filesets> 
        <fileset> 
         <directory>src/main/webapp/VAADIN/themes</directory> 
         <includes> 
          <include>**/styles.css</include> 
          <include>**/styles.scss.cache</include> 
         </includes> 
        </fileset> 
       </filesets> 
      </configuration> 
     </plugin> 

     <!-- The Jetty plugin allows us to easily test the development build by 
      running jetty:run on the command line. --> 
     <plugin> 
      <groupId>org.eclipse.jetty</groupId> 
      <artifactId>jetty-maven-plugin</artifactId> 
      <version>${jetty.plugin.version}</version> 
      <configuration> 
       <scanIntervalSeconds>2</scanIntervalSeconds> 
      </configuration> 
     </plugin> 
    </plugins> 

    <pluginManagement> 
     <plugins> 
      <!--This plugin's configuration is used to store Eclipse m2e settings 
       only. It has no influence on the Maven build itself. --> 
      <!-- TODO Remove when http://dev.vaadin.com/ticket/14924 is resolved --> 
      <plugin> 
       <groupId>org.eclipse.m2e</groupId> 
       <artifactId>lifecycle-mapping</artifactId> 
       <version>1.0.0</version> 
       <configuration> 
        <lifecycleMappingMetadata> 
         <pluginExecutions> 
          <pluginExecution> 
           <pluginExecutionFilter> 
            <groupId>com.vaadin</groupId> 
            <artifactId> 
             vaadin-maven-plugin 
            </artifactId> 
            <versionRange>[7.1.11,)</versionRange> 
            <goals> 
             <goal>resources</goal> 
             <goal>update-widgetset</goal> 
             <goal>compile</goal> 
             <goal>compile-theme</goal> 
             <goal>update-theme</goal> 
            </goals> 
           </pluginExecutionFilter> 
           <action> 
            <ignore></ignore> 
           </action> 
          </pluginExecution> 
         </pluginExecutions> 
        </lifecycleMappingMetadata> 
       </configuration> 
      </plugin> 
     </plugins> 
    </pluginManagement> 

</build>